#Spring: Swagger OpenAPI Specs

1 messages · Page 1 of 1 (latest)

covert fulcrum
#

Spring petclinic (rest version) has an openapi.yml file defined: https://github.com/spring-petclinic/spring-petclinic-rest/blob/master/src/main/resources/openapi.yml
Uptil now I've just been using swagger's annotations and making the DTOs myself, but using openapi.yml seems to be a better way.

Is using openapi.yml considered best practice? And are there tools that make generating them easier? (an alternative to typing out all of this myself)

GitHub

REST version of the Spring Petclinic sample application - spring-petclinic/spring-petclinic-rest

sullen trenchBOT
#

<@&1004656351647117403> please have a look, thanks.

tulip solar
#

Could you explain the question a little bit better? Is your question if having an openapi spec is a good idea and what the best way to create the yaml is?

final elm
#

@covert fulcrum
Using openapi.yml is Considered Best Practice ,
Updating the API specifications in a single openapi.yml file is more straightforward than managing so many annotations scattered across different files. It also makes it easier to refactor and maintain the codebase.
Try OpenAI generator : https://openapi-generator.tech/

Description will go into a meta tag in

covert fulcrum
# tulip solar Could you explain the question a little bit better? Is your question if having a...

A bit of both actually - so what I'm understanding is that the flow can be either way,
you either create a openapi.yml/json file and let spring handle the entities and daos for you OR you use annotations and let spring generate the openapi.yml file for you

What's considered the better way? I'm seeing both approaches being used, the repo I mentioned used openapi.yml with openapi-generator

ornate hare
#

You don't even need specific annotations if you let Spring generate it using openAPI.

#

There is no better way, it depends on your needs.

covert fulcrum
covert fulcrum
ornate hare
#

No, the other way around. Spring can fully generate your swagger page for you without special annotations.

covert fulcrum
#

Oh yeah, but that is a very bare-bones output right?

like I'll get id: string instead of ```
id: string
maxlength: xx
minlength: xx

sullen trenchBOT
ornate hare
#

It was more to point out you don't need to, just that you can.

covert fulcrum
#

Gotcha, yeah fair point

#

After inspecting a bit more, there may be some benefits to using openapi-generator though - openapi-generator adds validation to the getters and setters too, with lombok you only have validation for the constructors from what im seeing

#

that actually brings me to a question about the need for getters/setters - thanks simon and AJ appreciate the input