Please tell me this is the first time I’m writing openApi documentation and generating code from it. Almost everything worked as I planned, but I can substitute an example in the response, which returns the string type. This is an example of my endpoint description:
/getDictionaries:
get:
tags:
- Dictionaries
description: extrep_mdm.spk_get_rf_mrf_citizens
operationId: getSpkDictionary
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: string
examples:
someExample:
$ref: '#/components/examples/myExample'
And this is a component of the example:
components:
examples:
myExample:
summary: Test
value: 'test'
If I look through the swageer-editor, then everything looks correct and the example is filled in:
But when I generate code in my application, there is no block about examples:
And, accordingly, nothing changes in the swagger interface:
From this I concluded that I did not configure openapi-generator-maven-plugin correctly, here is how it is configured for me:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.6.0</version>
<executions>
<execution>
<id>generate-rest-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatorName>spring</generatorName>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<apiPackage>org.example.swagger.controller</apiPackage>
<modelPackage>org.example.swagger.model</modelPackage>
<generateSupportingFiles>true</generateSupportingFiles>
<generateApiDocumentation>true</generateApiDocumentation>
<generateApis>true</generateApis>
<generateModels>true</generateModels>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8-localdatetime</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
But I just can’t figure out where the error is, please tell me
OpenAPI Generator doesn't support
examples
(plural) in responses:https://github.com/OpenAPITools/openapi-generator/issues/16051
A possible workaround is to update your response definition to use a single
example
. Note that thisexample
must be an inline value and cannot use $refs.or