swagger-api / swagger-api/swagger-parser
resolveFully breaks 3.0 spec for headers via $ref in request and response
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Given the following files:
openapi: 3.0.3
info:
title: Sample API
version: 1.0.0
paths:
/users/:
get:
parameters:
- $ref: 'headers.yml#/XRequestId'
responses:
'200':
description: Ok
headers:
X-Request-Id:
$ref: 'headers.yml#/XRequestId'
and
XRequestId:
in: header
name: X-Request-Id
schema:
type: string
required: false
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolveFully(true);
var api = parser.read(file, null, options);
String content = Yaml.pretty(api);
the output will contain a $ref that cannot be resolved:
openapi: 3.0.3
info:
title: Sample API
version: 1.0.0
servers:
- url: /
paths:
/users/:
get:
parameters:
- name: X-Request-Id
in: header
required: false
schema:
type: string
responses:
"200":
description: Ok
headers:
X-Request-Id:
$ref: '#/components/headers/XRequestId'
components:
parameters:
XRequestId:
name: X-Request-Id
in: header
required: false
schema:
type: string
I know the in: is not valid for responses, but swagger-ui seems to be fine with it.
Surprisingly using version: 3.1.0 fixes that thing, unfortunately openapi-generator is not yet ready for that...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied Java reproduction using OpenAPIV3Parser and ParseOptions.setResolveFully(true), together with the two YAML files. Inspect how the request parameter and response header $ref values are resolved, then verify that the generated output contains no unresolved response-header reference while preserving the OpenAPI 3.0.3 structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100