Request Body Internal Ref Not Resolved
See original GitHub issueI’m not sure if this is a duplicate/related to #764 or #731.
Basically, when OpenApiV3Parser parses a post request body with a schema ref, the ref isn’t being resolved for the request body.
Here’s the openapi v3:
openapi: '3.0.0'
info:
title: Pet Store API
version: '3.0'
paths:
/adopt:
post:
requestBody:
$ref: '#/components/requestBodies/ASinglePet'
responses:
201:
$ref: '#/components/responses/Adopted'
components:
requestBodies:
ASinglePet:
description: Adoption Request
required: true
content:
application/petstore+json:
schema:
$ref: '#/components/schemas/AdoptionRequest'
responses:
Adopted:
description: Pet successfully adopted
content:
application/petstore+json:
schema:
$ref: '#/components/schemas/AdoptionResponse'
schemas:
Pets:
type: object
properties:
pets:
type: array
items:
$ref: '#/components/schemas/Pet'
Pet:
type: object
properties:
name:
type: string
example: Fluffy
AdoptionRequest:
description: Request to adopt a new pet
type: object
required:
- name
- pets
properties:
name:
description: Name pet store
type: string
pets:
$ref: '#/components/schemas/Pets'
AdoptionResponse:
description: Adoption Response
type: object
properties:
string:
description: Uri for the adopted pet
type: string
Here’s the request (formatted as a test 😉):
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/openApiSpec.yaml", null, parseOptions);
Content actualComponentContent = openAPI.getComponents().getRequestBodies().get("ASinglePet").getContent();
Content actualPathContent = openAPI.getPaths().get("/adopt").getPost().getRequestBody().getContent();
Map properties = actualComponentContent.get("application/petstore+json").getSchema().getProperties();
assertNotNull(properties);
assertEquals(properties.size(), 2);
assertNotNull(actualPathContent);
assertEquals(actualPathContent, actualComponentContent);
I’d expect the schema content to be populated under the path: /adopt/post/reqeustBody/content
, but instead it’s only the ref
populated.
If you want me to submit a PR for this I’d be more than happy. (I’m also not ruling out that I’m using ParseOptions, etc. correctly). 😄
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Request Body OneOf references not resolving correctly
When referencing Request Bodies in a OneOf the preview image shows "any" instead of the actual reference. If OneOf is required for the...
Read more >Cannot resolve a reference component schema defined in ...
When I'm trying to resolve reference in my YAML file. The references are not fully resolved and left as $ref in the request...
Read more >Describing Request Body - Swagger
GET, DELETE and HEAD are no longer allowed to have request body because it does not have defined semantics as per RFC 7231....
Read more >500 Internal Server Error - HTTP - MDN Web Docs - Mozilla
Sometimes, server administrators log error responses like the 500 status code with more details about the request to prevent the error from ...
Read more >API Reference - Express 4.x
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ), or an empty...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @nkringle,
Sorry for the confusion. setResolveFully(true) should solve the issue. It’s looks like a bug. I have fixed it, your test is passing now and request a PR #858 .
Thanks, Mohammed
Closed fix by #858