OpenAPI generate spring from swagger with "oneof" property - spring

I read already this thread:
How to use OpenAPI "oneOf" property with openapi-generator-maven-plugin when generating Spring code
But I still cant find a good working solution to generate Spring capable models from Swagger file with "oneof" properties.
I tried:
java -jar .\openapi-generator-cli.jar generate -i ./swagger.json -o ./spring-gen -g spring -c .\spring-config.json
with spring-config.json:
{
"legacyDiscriminatorBehavior":false
}
Did I miss something to get it working?
Is there a better/easy solution to get the models?
Open for any hints and thanks in advance!
Kind regards
Gregor

Related

Is there a way to generate API Documentation in YAML (not JSON) format using springfox?

For my springboot project, I am using OpenAPI 3.0.3 and springfox(3.0.3) for API documentation. I would like to generate the API documentation in YAML format, not JSON. By default, springfox generates JSON.
I have looked into using springdoc-openapi-ui instead of springfox (springdoc has the option of YAML format), but then I have to change all annotations and so on.
I was wondering if there is a way around it for telling springfox to generate yaml instead of json.
Thank you!
There is already a github issue with this query. Check out the discussion here for various possibilities -> https://github.com/springfox/springfox/issues/985
Another approach could be to take Springfox JSON and convert it to YAML using JSON2YAML converter as in https://www.json2yaml.com/.

Swagger-codegen : Can manual changes in the generated models be preserved?

With Swagger as i understand one cannot pass/specify things like Jackson annotations for fields when specifying the models in the swagger definition yaml.
Therefore, is there a way to manually make these changes in the generated model files & request swagger (swagger-codegen) to try & preserve those when regenerating the models?
I tried doing this & see that by default it just overwrites the files completely, i couldn't find any setting for this in the codegen configuration.
Can someone suggest any idea on how to go about this?
Thanks
You can use custom templates with the -t option, e.g.
java -jar swagger-codegen-cli.jar generate -i https://raw.githubusercontent.com/swagger-api/swagger-codegen/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l csharp -o C:\test\csharp-client -t C:\workspace\csharp-custom-templates
where C:\workspace\csharp-custom-templates stores the templates with your changes.

How to generate code from an openapi file?

is it possible to generate java code from the openapi definition file with quarkus?
Or should I use an external tool ?
Quarkus itself won't do that for you. You need to use another tool.
Have a look at https://github.com/OpenAPITools/openapi-generator. I don't think Quarkus can do that.
Quarkus could generate an openapi yaml file from your quarkus project, which you could again use for openapi client generation.
For that take a look here https://quarkus.io/guides/openapi-swaggerui
This project is now available: https://github.com/quarkiverse/quarkus-openapi-generator. Works as expected.

Auto generate REST api documentation into RAML from Spring MVC controllers

I am new to Spring-Boot. I want to auto generate my REST api documentation into RAML from my Spring MVC controllers. Is there anything to do that? or any guide that I could use it for generating my rest api into RAML?
There is a Spring REST Docs to RAML extension for Spring REST Docs: https://github.com/ePages-de/restdocs-raml However, this project is not maintained anymore and the authors recommend to use their new project https://github.com/ePages-de/restdocs-openapi that converts to OpenAPI (Swagger) instead of RAML. They provide a guide on how to convert OpenAPI to RAML: https://github.com/ePages-de/restdocs-openapi#convert-to-raml There is an example project that demonstrates the conversion to OpenAPI and RAML https://github.com/ePages-de/restdocs-openapi/tree/master/samples/restdocs-openapi-sample One limitation of the extension is that it only works with Gradle at the moment.
I know, your Question is outdated, but there is something that might help.
You can use DocDog. From there it creates RAML from the existing source code. If it is SpringBoot you can run it easily with -lang=spring. If it is plain JAVA you can add comments to your code (see readme.md or examples), so DogDoc can understand.
May it helps you: https://github.com/skalski/docdog

katharsis configured with spring xml

It looks, from the source code, that Katharsis-spring module will only work with spring boot.
My question then, is it possible to configure a spring project in xml and load Katharsis without spring boot?
If so, how would you need to configure katharsis in spring xml?
Has anyone done this before and willing to share an example?
Thanks.
Only work with Spring boot? That doesn't seem possible. Just #Import(KatharsisConfigV2.class) on any configuration in your code and it should work.
As for xml config: By design, if it can be done in code it can be done in config.
Try that and let me know how you make out
With version 2.8.1 of katharsis, it is quite a challege to get this configured just in xml. So I looked at the master branch of the project and found that there are going to be some new features which will make it easier to configure with spring xml. I have created a sample project here you can use as reference for configuration:
Sample Spring/Katharsis Project with XML configuration
In the sample project I added the SpringServiceDiscovery class, and modified the KatharsisBoot class to make the configuration easier. With the next release of this project, I should be able to remove these 2 classes completely, and use the classes that come with katharsis.
The beans I needed to add to my root-context.xml file were the following:
io.katharsis.spring.KatharsisFilterV2
io.katharsis.spring.ErrorHandlerFilter
com.springkatharsisxml.katharsis.boot.KatharsisBoot
io.katharsis.queryParams.QueryParamsBuilder
io.katharsis.resource.registry.ConstantServiceUrlProvider
io.katharsis.queryParams.DefaultQueryParamsParser
io.katharsis.module.CoreModule
io.katharsis.resource.field.ResourceFieldNameTransformer
io.katharsis.spring.boot.KatharsisSpringBootProperties
I also needed to expose the jackson objectMapper bean, as it's not done so by default in xml.
I also used the org.springframework.web.filter.DelegatingFilterProxy for the katharsisFilter and errorHandlerFilter.

Resources