swagger-parser
swagger-parser copied to clipboard
Swagger conversion to OpenAPI3 with `allOf` makes `required` of the composed model get lost
Swagger-parser version: 2.1.2
Sample spec
swagger: "2.0"
info:
title: composed model conversion test
version: 1.0.0
paths:
/composed:
get:
operationId: composed
responses:
"200":
description: OK
schema:
$ref: "#/definitions/ComposedModel"
definitions:
BaseModel:
type: object
required:
- uuid
properties:
uuid:
type: string
ComposedModel:
type: object
required:
- name
allOf:
- $ref: "#/definitions/BaseModel"
properties:
name:
type: string
Description
Having a Swagger 2 specification that has a composed model (such as having an allOf
) and converting that to OpenAPI 3 makes sure information is properly transformed into the new ComposedSchema, except for required
. So the required
properties information gets lost after conversion when it is being composed.
Expected result
I expected to keep required
in there.
Actual result
No required
to be found on ComposedModel
.
Parsing result:
{
"openapi": "3.0.1",
"info": {
"title": "composed model conversion test",
"version": "1.0.0",
"extensions": {}
},
"servers": [{ "url": "/" }],
"paths": {
"/composed": {
"get": {
"operationId": "composed",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/ComposedModel",
"extensions": {},
"exampleSetFlag": false
},
"exampleSetFlag": false
}
},
"extensions": {}
}
},
"extensions": {}
},
"extensions": {}
}
},
"components": {
"schemas": {
"BaseModel": {
"required": ["uuid"],
"type": "object",
"properties": {
"uuid": {
"type": "string",
"extensions": {},
"exampleSetFlag": false,
"types": ["string"]
}
},
"exampleSetFlag": false,
"types": ["object"],
"jsonSchema": {
"type": "object",
"required": ["uuid"],
"properties": { "uuid": { "type": "string" } }
}
},
"ComposedModel": {
"properties": {
"name": {
"type": "string",
"extensions": {},
"exampleSetFlag": false,
"types": ["string"]
}
},
"extensions": {},
"exampleSetFlag": false,
"allOf": [
{ "$ref": "#/components/schemas/BaseModel", "exampleSetFlag": false }
]
}
}
},
"extensions": { "x-original-swagger-version": "2.0" }
}
using
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Include.NON_NULL);
String json = mapper.writeValueAsString(openapi);