swagger-api / swagger-api/swagger-codegen-generators
Trivial java type path parameters specified by $ref does not work.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
We recently received a yaml interface specification where we need to make a java client to integrate with the service provided. The authors have probably used the online editor, which shows everything in perfectly order, but they have clearly not tried to use swagger to make a java client.
The problem we're facing is, that they have used path parameters defined by referencing components that boils down to a "trivial type". By trivial type, i mean a type that can be converted to and from a String that can be passed as a part of a URL path. However, the java code generator creates objects for these components and these objects toString applies "class FooReference ..." and a whole lot of debug friendly information to the string which does not go well in a path.
Example:
openapi: '3.0.0'
info:
title: Non working path parameter
description:
version: 1.0.4
paths:
/foo/{barId}/bleh:
get:
parameters:
- in: path
name: barId
required: true
schema:
$ref: '#/components/schemas/BarReference'
responses:
'200':
description: Ok.
'404':
description: No such fubar.
default:
description: Unexpected error.
components:
schemas:
BarReference:
properties:
barId:
type: string
description: Identifier for the foobar.
required:
- barId
generates a BarReference java class with:
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class BarReference {\n");
sb.append(" barId: ").append(toIndentedString(barId)).append("\n");
sb.append("}");
return sb.toString();
}
and these objects are turned into the a path piece just by calling toString.
I'm not sure if this is expected behaviour and an errornous usage of $ref from the authors of the yaml file or a java code generator problem. I do know that we're unable to use swagger to create a functional API for this interface.
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 Java generator's handling of path parameters and the generated BarReference class shown in the issue. Reproduce the supplied OpenAPI YAML, inspect how the referenced parameter becomes a URL path value, and verify that the generated client uses the underlying trivial value rather than the object's debug-style toString output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100