Swagger API Tools: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 32: Line 32:


<syntaxhighlight lang='java'>
<syntaxhighlight lang='java'>
String s = Json.pretty(swagger);
String s = Yaml.pretty(swagger);
</syntaxhighlight>
</syntaxhighlight>



Revision as of 03:02, 23 February 2019

External

Internal

Swagger Core

OpenAPI 3.0 implementation https://github.com/swagger-api/swagger-core
OpenAPI 2.0 implementation https://github.com/swagger-api/swagger-core/tree/1.5

Swagger Core Playground Example

https://github.com/ovidiuf/playground/tree/master/swagger/swagger-parser-example

Render Swagger as Yaml

Render Swagger as Yaml
import io.swagger.models.Swagger;
import io.swagger.util.Yaml;

Swagger swagger = ...
String s = Yaml.mapper().writeValueAsString(swagger);

Alternative:

String s = Yaml.pretty(swagger);

Render Swagger as Json

Render Swagger as Json
import io.swagger.models.Swagger;
import io.swagger.util.Json;

Swagger swagger = ...
String s = Json.mapper().writeValueAsString(swagger);

Alternative:

String s = Json.pretty(swagger);

Swagger Parser

Swagger Parser 1.X (OpenAPI 2.0) https://github.com/swagger-api/swagger-parser/tree/v1
Swagger Parser 2.X (OpenAPI 3.0) https://github.com/swagger-api/swagger-parser

Swagger Parser Overview

Swagger Parser dependes on Swagger Core.

Swagger Parser Playground Example

https://github.com/ovidiuf/playground/tree/master/swagger/swagger-parser-example

Dependencies

dependencies {

    implementation "io.swagger:swagger-parser:1.0.42"
    implementation "io.swagger:swagger-parser:1.0.42:sources"

}