File tree Expand file tree Collapse file tree
src/languageservice/parser Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1377,7 +1377,21 @@ function validate(
13771377 ( schema . type === 'object' && schema . additionalProperties === undefined && options . disableAdditionalProperties === true )
13781378 ) {
13791379 if ( unprocessedProperties . length > 0 ) {
1380- const possibleProperties = schema . properties && Object . keys ( schema . properties ) . filter ( ( prop ) => ! seenKeys [ prop ] ) ;
1380+ const possibleProperties =
1381+ schema . properties &&
1382+ Object . entries ( schema . properties )
1383+ . filter ( ( [ key , property ] ) => {
1384+ // don't include existing properties
1385+ if ( seenKeys [ key ] ) {
1386+ return false ;
1387+ }
1388+ // don't include properties that are not suggested in completion
1389+ if ( property && typeof property === 'object' && ( property . doNotSuggest || property . deprecationMessage ) ) {
1390+ return false ;
1391+ }
1392+ return true ;
1393+ } )
1394+ . map ( ( [ key ] ) => key ) ;
13811395
13821396 for ( const propertyName of unprocessedProperties ) {
13831397 const child = seenKeys [ propertyName ] ;
Original file line number Diff line number Diff line change @@ -1686,6 +1686,46 @@ obj:
16861686 ] ) ;
16871687 } ) ;
16881688
1689+ it ( 'should return error with possible props' , async ( ) => {
1690+ const schema = {
1691+ type : 'object' ,
1692+ properties : {
1693+ // prop0 is missing, should be added as a possible prop
1694+ prop0 : {
1695+ type : 'string' ,
1696+ } ,
1697+ // prop1 is already defined in the yaml
1698+ prop1 : {
1699+ type : 'string' ,
1700+ } ,
1701+ // prop2 is not suggested
1702+ prop2 : {
1703+ type : 'string' ,
1704+ doNotSuggest : true ,
1705+ } ,
1706+ // prop3 is deprecated
1707+ prop3 : {
1708+ type : 'string' ,
1709+ deprecationMessage : 'prop3 is deprecated' ,
1710+ } ,
1711+ } ,
1712+ } ;
1713+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
1714+ const content = `prop1: value1\npropX: you should not be there 'propX'` ;
1715+ const result = await parseSetup ( content ) ;
1716+ expect (
1717+ result . map ( ( r ) => ( {
1718+ message : r . message ,
1719+ properties : ( r . data as { properties : unknown } ) ?. properties ,
1720+ } ) )
1721+ ) . to . deep . eq ( [
1722+ {
1723+ message : 'Property propX is not allowed.' ,
1724+ properties : [ 'prop0' ] ,
1725+ } ,
1726+ ] ) ;
1727+ } ) ;
1728+
16891729 it ( 'should allow additional props on object when additionalProp is true on object' , async ( ) => {
16901730 const schema = {
16911731 type : 'object' ,
You can’t perform that action at this time.
0 commit comments