Springdoc OpenAPI Programmatic Documenation

Allows for defining OpenAPI documentation using code

License

License

Categories

Categories

springdoc-openapi Program Interface REST Frameworks
GroupId

GroupId

com.danielfrak.code
ArtifactId

ArtifactId

springdoc-openapi-programmatic-documentation
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Springdoc OpenAPI Programmatic Documenation
Allows for defining OpenAPI documentation using code
Project URL

Project URL

https://www.code.danielfrak.com
Source Code Management

Source Code Management

https://github.com/daniel-frak/Springdoc-OpenAPI-Programmatic-Documentation

Download springdoc-openapi-programmatic-documentation

How to add to project

<!-- https://jarcasting.com/artifacts/com.danielfrak.code/springdoc-openapi-programmatic-documentation/ -->
<dependency>
    <groupId>com.danielfrak.code</groupId>
    <artifactId>springdoc-openapi-programmatic-documentation</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.danielfrak.code/springdoc-openapi-programmatic-documentation/
implementation 'com.danielfrak.code:springdoc-openapi-programmatic-documentation:1.0.1'
// https://jarcasting.com/artifacts/com.danielfrak.code/springdoc-openapi-programmatic-documentation/
implementation ("com.danielfrak.code:springdoc-openapi-programmatic-documentation:1.0.1")
'com.danielfrak.code:springdoc-openapi-programmatic-documentation:jar:1.0.1'
<dependency org="com.danielfrak.code" name="springdoc-openapi-programmatic-documentation" rev="1.0.1">
  <artifact name="springdoc-openapi-programmatic-documentation" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.danielfrak.code', module='springdoc-openapi-programmatic-documentation', version='1.0.1')
)
libraryDependencies += "com.danielfrak.code" % "springdoc-openapi-programmatic-documentation" % "1.0.1"
[com.danielfrak.code/springdoc-openapi-programmatic-documentation "1.0.1"]

Dependencies

provided (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter jar 2.1.0.RELEASE
io.swagger.core.v3 : swagger-core jar 2.1.0

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-engine jar 5.5.0
org.mockito : mockito-core jar 3.2.4
org.mockito : mockito-junit-jupiter jar 3.2.4

Project Modules

There are no modules declared in this project.

Springdoc OpenAPI Programmatic Documentation library

Code Soapbox logo

Introduction

This library is an extension for Springdoc OpenAPI which allows for defining OpenAPI 3.0 schema using code.

However, while it was developed with Springdoc OpenAPI in mind, you can apply this solution to any Spring Boot OpenAPI library based on Spring Core.

Getting Started

  1. Add a dependency on springdoc-openapi-programmatic-documentation:
<dependency>
  <groupId>com.danielfrak.code</groupId>
  <artifactId>springdoc-openapi-programmatic-documentation</artifactId>
  <version>1.0.1</version>
</dependency>
  1. Inject a ModelDocumentation instance in a @configuration class and use it to add a new schema:
import io.swagger.v3.oas.models.media.Schema;
import org.springframework.context.annotation.Configuration;
import com.danielfrak.code.config.openapi.ModelDocumentation;
import com.danielfrak.code.config.openapi.ModelDocumentation.Model;
import com.danielfrak.code.model.MyValueObject;

@Configuration
public class OpenApiConfig {

    public OpenApiConfig(ModelDocumentation modelDocumentation) {
        modelDocumentation
                .add(new DocumentedModel()
                        .source(MyValueObject.class)
                        .implementation(String.class)
                        .schema(new Schema<>()
                                .example("Example value")
                                .description("Base description")));
    }
}

DocumentedModel fields

  • source - the class to document
  • implementation - equivalent to the implementation on @io.swagger.v3.oas.annotations.media.Schema
  • schema - an io.swagger.v3.oas.models.media.Schema instance to serve as the final schema for the source class

Versions

Version
1.0.1