diff --git a/.changeset/oas32-media-type-description.md b/.changeset/oas32-media-type-description.md new file mode 100644 index 0000000000..64a118c621 --- /dev/null +++ b/.changeset/oas32-media-type-description.md @@ -0,0 +1,6 @@ +--- +'@redocly/openapi-core': patch +'@redocly/cli': patch +--- + +Added support for the `description` field of the Media Type Object in OpenAPI 3.2. diff --git a/packages/core/src/types/oas3_2.ts b/packages/core/src/types/oas3_2.ts index d82d753af0..261c52529f 100755 --- a/packages/core/src/types/oas3_2.ts +++ b/packages/core/src/types/oas3_2.ts @@ -231,6 +231,7 @@ const MediaType: NodeType = { ...Oas3_1Types.MediaType, properties: { ...Oas3_1Types.MediaType.properties, + description: { type: 'string' }, itemSchema: 'Schema', prefixEncoding: listOf('Encoding', { description: diff --git a/tests/e2e/lint/oas3.2/openapi.yaml b/tests/e2e/lint/oas3.2/openapi.yaml index f4ab647b59..e63ee7335c 100644 --- a/tests/e2e/lint/oas3.2/openapi.yaml +++ b/tests/e2e/lint/oas3.2/openapi.yaml @@ -53,6 +53,7 @@ paths: required: true content: application/json: + description: Should allow a description in a Media Type Object (OpenAPI 3.2) schema: type: object properties: diff --git a/tests/e2e/lint/oas3.2/snapshot.txt b/tests/e2e/lint/oas3.2/snapshot.txt index 0cc51888be..90a766a404 100644 --- a/tests/e2e/lint/oas3.2/snapshot.txt +++ b/tests/e2e/lint/oas3.2/snapshot.txt @@ -102,74 +102,74 @@ Property `wrong` is not expected here. Error was generated by the struct rule. -[8] openapi.yaml:110:25 at #/paths/~1thing/get/responses/200/content/multipart~1form-data/encoding/addresses/itemEncoding/encoding/street/wrong +[8] openapi.yaml:111:25 at #/paths/~1thing/get/responses/200/content/multipart~1form-data/encoding/addresses/itemEncoding/encoding/street/wrong Property `wrong` is not expected here. -108 | street: -109 | contentType: text/plain -110 | wrong: Should catch wrong fields in a nested Encoding Object! +109 | street: +110 | contentType: text/plain +111 | wrong: Should catch wrong fields in a nested Encoding Object! | ^^^^^ -111 | application/jsonl: -112 | $ref: '#/components/mediaTypes/StreamingPets' +112 | application/jsonl: +113 | $ref: '#/components/mediaTypes/StreamingPets' Error was generated by the struct rule. -[9] openapi.yaml:147:7 at #/components/mediaTypes/StreamingPets/wrong +[9] openapi.yaml:148:7 at #/components/mediaTypes/StreamingPets/wrong Property `wrong` is not expected here. -145 | itemSchema: -146 | type: object -147 | wrong: Should catch wrong fields in a Media Type Object in components! +146 | itemSchema: +147 | type: object +148 | wrong: Should catch wrong fields in a Media Type Object in components! | ^^^^^ -148 | securitySchemes: -149 | petstore_auth: +149 | securitySchemes: +150 | petstore_auth: -referenced from openapi.yaml:112:15 at #/paths/~1thing/get/responses/200/content/application~1jsonl +referenced from openapi.yaml:113:15 at #/paths/~1thing/get/responses/200/content/application~1jsonl Error was generated by the struct rule. -[10] openapi.yaml:180:9 at #/components/schemas/MyResponseType/discriminator/wrong +[10] openapi.yaml:181:9 at #/components/schemas/MyResponseType/discriminator/wrong Property `wrong` is not expected here. -178 | propertyName: petType -179 | defaultMapping: OtherPet # Should be allowed -180 | wrong: Should catch a wrong field in discriminator! +179 | propertyName: petType +180 | defaultMapping: OtherPet # Should be allowed +181 | wrong: Should catch a wrong field in discriminator! | ^^^^^ -181 | Lizard: -182 | type: object +182 | Lizard: +183 | type: object Error was generated by the struct rule. -[11] openapi.yaml:156:11 at #/components/securitySchemes/petstore_auth/flows/implicit/wrong +[11] openapi.yaml:157:11 at #/components/securitySchemes/petstore_auth/flows/implicit/wrong Property `wrong` is not expected here. -154 | implicit: -155 | authorizationUrl: https://example.org/api/oauth/dialog -156 | wrong: Should catch wrong prop in oauth2 flows! +155 | implicit: +156 | authorizationUrl: https://example.org/api/oauth/dialog +157 | wrong: Should catch wrong prop in oauth2 flows! | ^^^^^ -157 | scopes: -158 | write:pets: modify pets in your account +158 | scopes: +159 | write:pets: modify pets in your account Error was generated by the struct rule. -[12] openapi.yaml:168:9 at #/components/securitySchemes/device_auth/flows/deviceAuthorization +[12] openapi.yaml:169:9 at #/components/securitySchemes/device_auth/flows/deviceAuthorization The field `scopes` must be present on this level. -166 | type: oauth2 -167 | flows: -168 | deviceAuthorization: +167 | type: oauth2 +168 | flows: +169 | deviceAuthorization: | ^^^^^^^^^^^^^^^^^^^ -169 | # scopes: Scopes are required in deviceAuthorization! -170 | deviceAuthorizationUrl: http://localhost +170 | # scopes: Scopes are required in deviceAuthorization! +171 | deviceAuthorizationUrl: http://localhost Error was generated by the struct rule. @@ -237,16 +237,16 @@ Warning was generated by the operation-operationId rule. Reference: https://redocly.com/docs/cli/rules/oas/operation-operationId -[17] openapi.yaml:65:7 at #/paths/~1products/query/responses +[17] openapi.yaml:66:7 at #/paths/~1products/query/responses Operation must have at least one `4XX` response. -63 | items: -64 | type: string -65 | responses: +64 | items: +65 | type: string +66 | responses: | ^^^^^^^^^ -66 | '200': -67 | description: Search results +67 | '200': +68 | description: Search results Warning was generated by the operation-4xx-response rule. @@ -269,112 +269,112 @@ Warning was generated by the operation-operationId rule. Reference: https://redocly.com/docs/cli/rules/oas/operation-operationId -[19] openapi.yaml:70:5 at #/paths/~1stream/get/operationId +[19] openapi.yaml:71:5 at #/paths/~1stream/get/operationId Operation object should contain `operationId` field. -68 | summary: Should allow summary in responses -69 | /stream: -70 | get: +69 | summary: Should allow summary in responses +70 | /stream: +71 | get: | ^^^ -71 | summary: Stream -72 | responses: +72 | summary: Stream +73 | responses: Warning was generated by the operation-operationId rule. Reference: https://redocly.com/docs/cli/rules/oas/operation-operationId -[20] openapi.yaml:72:7 at #/paths/~1stream/get/responses +[20] openapi.yaml:73:7 at #/paths/~1stream/get/responses Operation must have at least one `4XX` response. -70 | get: -71 | summary: Stream -72 | responses: +71 | get: +72 | summary: Stream +73 | responses: | ^^^^^^^^^ -73 | 200: -74 | description: Stream of updates +74 | 200: +75 | description: Stream of updates Warning was generated by the operation-4xx-response rule. Reference: https://redocly.com/docs/cli/rules/oas/operation-4xx-response -[21] openapi.yaml:83:5 at #/paths/~1thing/get/operationId +[21] openapi.yaml:84:5 at #/paths/~1thing/get/operationId Operation object should contain `operationId` field. -81 | data: { type: object } -82 | /thing: -83 | get: +82 | data: { type: object } +83 | /thing: +84 | get: | ^^^ -84 | summary: a sample api -85 | responses: +85 | summary: a sample api +86 | responses: Warning was generated by the operation-operationId rule. Reference: https://redocly.com/docs/cli/rules/oas/operation-operationId -[22] openapi.yaml:85:7 at #/paths/~1thing/get/responses +[22] openapi.yaml:86:7 at #/paths/~1thing/get/responses Operation must have at least one `4XX` response. -83 | get: -84 | summary: a sample api -85 | responses: +84 | get: +85 | summary: a sample api +86 | responses: | ^^^^^^^^^ -86 | '200': -87 | description: OK +87 | '200': +88 | description: OK Warning was generated by the operation-4xx-response rule. Reference: https://redocly.com/docs/cli/rules/oas/operation-4xx-response -[23] openapi.yaml:173:5 at #/components/schemas/MyResponseType +[23] openapi.yaml:174:5 at #/components/schemas/MyResponseType Component: "MyResponseType" is never used. -171 | tokenUrl: http://localhost -172 | schemas: -173 | MyResponseType: +172 | tokenUrl: http://localhost +173 | schemas: +174 | MyResponseType: | ^^^^^^^^^^^^^^ -174 | oneOf: -175 | - $ref: '#/components/schemas/Lizard' +175 | oneOf: +176 | - $ref: '#/components/schemas/Lizard' Warning was generated by the no-unused-components rule. Reference: https://redocly.com/docs/cli/rules/oas/no-unused-components -[24] openapi.yaml:149:5 at #/components/securitySchemes/petstore_auth +[24] openapi.yaml:150:5 at #/components/securitySchemes/petstore_auth Security scheme: "petstore_auth" is never used. -147 | wrong: Should catch wrong fields in a Media Type Object in components! -148 | securitySchemes: -149 | petstore_auth: +148 | wrong: Should catch wrong fields in a Media Type Object in components! +149 | securitySchemes: +150 | petstore_auth: | ^^^^^^^^^^^^^ -150 | type: oauth2 -151 | deprecated: true # Should allow deprecation +151 | type: oauth2 +152 | deprecated: true # Should allow deprecation Warning was generated by the no-unused-components rule. Reference: https://redocly.com/docs/cli/rules/oas/no-unused-components -[25] openapi.yaml:160:5 at #/components/securitySchemes/api_key +[25] openapi.yaml:161:5 at #/components/securitySchemes/api_key Security scheme: "api_key" is never used. -158 | write:pets: modify pets in your account -159 | read:pets: read your pets -160 | api_key: +159 | write:pets: modify pets in your account +160 | read:pets: read your pets +161 | api_key: | ^^^^^^^ -161 | type: apiKey -162 | in: header +162 | type: apiKey +163 | in: header Warning was generated by the no-unused-components rule.