swagger-api / swagger-api/swagger-codegen
[3.0.7] Swagger codegen generated code misses method for certain media type
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I'm trying to build a REST api versioned by mediatypes using Swagger 3. I want to return different objects depending on the accept header within the request.
So I created a yaml file in http://editor.swagger.io and generated the server code (jaxrs-cxf). But the generated code always only contains a method for the first object type.
Swagger-codegen version
3.0.7
Swagger declaration file content or url
I broke it down to a fairly simple yaml file. When generating the server code, only one method is generated:
openapi: 3.0.2
info:
title: pet test api
description: testapi for mime based versioning
version: 1.0.0
servers:
- url: https://animal.com/pets
paths:
/pet:
get:
tags:
- pets
summary: pets
description: get cat or dog
responses:
'200':
description: get specific pet
content:
application/cat+json:
schema:
$ref: '#/components/schemas/cat'
application/dog+json:
schema:
$ref: '#/components/schemas/dog'
components:
schemas:
cat:
type: object
properties:
id:
type: integer
name:
type: string
dog:
type: object
properties:
name:
type: string
age:
type: integer
My expectation would be to get at least two methods generated within main/java/io.swagger.api.impl.PetsApiServiceImpl.java
public class PetsApiServiceImpl implements PetsApi {
/**
* pets
*
* get cat or dog
*
*/
public Cat petGet() {
// TODO: Implement...
return null;
}
public Dog petGet() {
// TODO: Implement...
return null;
}
}
But actually only one method is being generated:
public class PetsApiServiceImpl implements PetsApi {
/**
* pets
*
* get cat or dog
*
*/
public Cat petGet() {
// TODO: Implement...
return null;
}
}
To be honest, this is the first time I use swagger.
So is my expectation wrong, and what I want to archive is simply not possible? Or is this a bug within the swagger codegen?
Thanks, Jan
Command line used for generation
java -jar swagger-codegen-cli.jar generate -l jaxrs-cxf -i catdog.yml
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
Run the reported java -jar swagger-codegen-cli.jar generate -l jaxrs-cxf -i catdog.yml command using the supplied OpenAPI document, then inspect main/java/io.swagger.api.impl.PetsApiServiceImpl.java. Trace how the two response media types are represented in the generated API and determine the supported behavior for this case. Done means the behavior is covered by an appropriate regression test or the issue is clearly documented as unsupported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100