swagger-core
swagger-core copied to clipboard
FQN doesn't work properly
There is a bug when initializing a new Schema. Dependent on the $ref the Schema-Class adds #/components/schemas/ to the reference or not. But this logic is failing in case of full qualified class names.
https://github.com/swagger-api/swagger-core/blob/1b1e2a2b03b699d3c75f15f445b4e59877ab998f/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java#L610
Fix would be:
public class Schema<T> {
...
public void set$ref(String $ref) {
if($ref != null && !$ref.contains(Components.COMPONENTS_SCHEMAS_REF)){
$ref = Components.COMPONENTS_SCHEMAS_REF + $ref;
}
this.$ref = $ref;
}
...
}
another approach is to fix https://github.com/swagger-api/swagger-core/blob/1b1e2a2b03b699d3c75f15f445b4e59877ab998f/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java#L1401
As you can see the call to new Schema().$ref(xy) is done without using the static method constructRef (example where its done the right way: https://github.com/swagger-api/swagger-core/blob/1b1e2a2b03b699d3c75f15f445b4e59877ab998f/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java#L257)
In case the fix should be done in the ModelResolver it can be easy applied with:
Schema refSchema = new Schema().$ref(constructRef(model.getName()));
Thanks for reporting and investigating this. Can you possibly add a PR? In case, I'd probably go for your option 1 with fix on Schema class
@kevinpeter hi! Is this still an issue for you? Going through some old issues.