I'm using SpringDoc and trying to add a schema to OpenApi programmatically, but no success.
@Bean
public OpenAPI customOpenAPI() {
Schema mySchema = new Schema<Object>();
mySchema
.type("object")
.$ref("#/components/schemas/MySchema")
.name("MySchema")
.addProperties("testStr", new StringSchema());
return new OpenAPI()
.servers(servers)
.info(new Info().title(title).version(version).description(description))
.components(new Components()
.addSchemas("MySchema" , mySchema)
)
.tags(tags);
}
The description of mySchema is not added to the list of schemas I see in the YAML file generated and if I try to ref to it:
apiResponses.entrySet().forEach(response -> response.getValue().addHeaderObject("XxX",
new Header().$ref("#/components/schemas/MySchema")));
Following error is displayed in swagger UI:
Resolver error at paths./XX/v1/test/status/{entry}.get.responses.404.headers.XxX.$ref Could not resolve reference: Could not resolve pointer: /components/schemas/MySchema
Please, could you help me to understand?
Edit:
I'm using version 1.3.9