Closed david0 closed 1 month ago
Another variation of this bug with nested allOf
/anyOf
:
openapi: 3.0.0
info:
title: Minimal OpenAPI 3.0 with allOf
version: 1.0.0
paths:
/pets:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PetCreate'
responses:
'201':
description: Created
components:
schemas:
Pet:
type: object
properties:
id:
type: integer
Cow:
type: object
PetCreate:
allOf:
- anyOf:
- $ref: '#/components/schemas/Pet'
- $ref: '#/components/schemas/Cow'
- properties:
name:
type: string
@Test
public void allOfAnyOfResolveFully() {
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("required-anyOf.yaml", null, options);
RequestBody requestBody = openAPI.getPaths().get("/pets").getPost().getRequestBody();
Schema requestBodySchema = requestBody.getContent().get("application/json").getSchema();
assertNull(requestBodySchema.get$ref()); // has been inlined
Schema schema = requestBody.getContent().get("application/json").getSchema();
assertEquals(schema.getProperties().size(),2); // <!--FAILS, since id got lost
}
We are trying to enforce some properties via
required
together withallOf
to reuse existing definitions:But using
setResolveFully(true)
, therequired
attribute will get lost: