Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Examples and comparison of how a REST API can be documented with different technologies

License

NotificationsYou must be signed in to change notification settings

pe-st/apidocs

Repository files navigation

Build Status

Overview

Let’s say that you’re given the task of writing a microserviceAND providing a documentationin OpenAPI format. You already know that there are two main approaches:

  • design-first : write the OpenAPI document (a.k.a. theopenapi.yaml file) and then generate the code

  • code-first : write the code, using OpenAPI annotations, and then generate the OpenAPI document

This repository contains different implementations of a simple service to demonstrate differencesbetween the design-first and code-first approach.

The examples useQuarkus as serverjust because it not only supports MicroProfile OpenAPI, but comes also with an integrated UI.But the examples should run with very few code changes in any MicroProfile compatible server.

Project Structure

The example projects all work without the parent umbrella project, so you can easily copy just theexample you’re interested in and start modifying it.

All example projects have integration tests (inOpenapiDocumentIT.java) that check the result ofthe/openapi endpoint. Not only protects this from silent changes due to a changed implementationwhen the project dependencies are updated (like it happened when I updated from Quarkus 0.21.1 to0.23.2), but it allows also to easily compare the differences between the example projects:

  • every project contains asrc/test/resources/openapi-sorted.yaml file with a little bit normalizedOpenAPI document (sorting YAML files ist not trivial…​)

  • thedesign-first projects contain also the generated POJO files asXxx.java.txt files(the txt suffix protects them from being recognized as Java files by the IDE and being reformatted),allowing to compare the result of openapi-generator and swagger-codegen.

In addition, all example projects have arest-api.http file which allows to run some example HTTPrequest against a running service directly from within IntelliJ. And there is an_idea directorycontaining the IntelliJ project setup. But you can import the projects easily in any IDE with Mavensupport.

Comparison

Comparison between the examples using code-first and design-first approach

SolutionProsCons

code-first

  • No need to learn OpenAPI Documents

  • Project can just be opened in the IDE (No need to generate code first)

  • Portability: not every scanner creates the sameopenapi.yaml

  • Portability: minor differences between Swagger and MicroProfile annotations

  • Boilerplate and code duplication

design-first

  • One source of truth:Code, Documentation and Annotations generated from the same information

  • can generate also Bean Validation annotations and Javadoc

  • Learning Effort

  • IDE integration not optimal yet

About

Examples and comparison of how a REST API can be documented with different technologies

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp