Skip to content

Commit

Permalink
chore(deps): update restdocs-api-spec to v0.19.0
Browse files Browse the repository at this point in the history
Adds support for `contact` object in the mojo parameters.
  • Loading branch information
klieber committed Oct 9, 2023
1 parent 580b902 commit f56a4d5
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<maven.compiler.target>17</maven.compiler.target>
<maven.version>3.3.1</maven.version>
<maven-plugin-tools.version>3.9.0</maven-plugin-tools.version>
<restdocs-api-spec.version>0.17.1</restdocs-api-spec.version>
<restdocs-api-spec.version>0.19.0</restdocs-api-spec.version>
<junit.version>5.10.0</junit.version>
<assertj.version>3.24.2</assertj.version>
<mockito.version>5.6.0</mockito.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class ApiDetails {

Expand All @@ -20,6 +21,8 @@ public class ApiDetails {
private SpecificationFormat format;
private AuthConfig authConfig;
private List<Tag> tags;

private Contact contact;

public ApiDetails() {
this.name = DEFAULT_NAME;
Expand All @@ -30,6 +33,7 @@ public ApiDetails() {
this.format = DEFAULT_FORMAT;
this.authConfig = new AuthConfig();
this.tags = Collections.emptyList();
this.contact = null;
}

public String getName() {
Expand Down Expand Up @@ -112,4 +116,13 @@ public ApiDetails tags(List<Tag> tags) {
this.tags = tags != null ? tags : this.tags;
return this;
}

public Optional<Contact> getContact() {
return Optional.ofNullable(contact);
}

public ApiDetails contact(Contact contact) {
this.contact = contact;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.berkleytechnologyservices.restdocs.spec;

public class Contact {

private String name;
private String email;
private String url;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.berkleytechnologyservices.restdocs.spec.generator.openapi_v3;

import com.berkleytechnologyservices.restdocs.spec.ApiDetails;
import com.berkleytechnologyservices.restdocs.spec.Contact;
import com.berkleytechnologyservices.restdocs.spec.Specification;
import com.berkleytechnologyservices.restdocs.spec.generator.SpecificationGenerator;
import com.berkleytechnologyservices.restdocs.spec.generator.SpecificationGeneratorException;
Expand Down Expand Up @@ -43,7 +44,8 @@ public String generate(ApiDetails details, List<ResourceModel> models) throws Sp
SpecificationGeneratorUtils.createTagDescriptionsMap(details.getTags()),
details.getVersion(),
SpecificationGeneratorUtils.createOauth2Configuration(details.getAuthConfig()),
details.getFormat().name().toLowerCase()
details.getFormat().name().toLowerCase(),
details.getContact().map(this::toSwaggerContact).orElse(null)
);
}

Expand All @@ -59,4 +61,9 @@ private List<Server> createServerList(ApiDetails details) throws SpecificationGe
}
return servers;
}

private io.swagger.v3.oas.models.info.Contact toSwaggerContact(Contact contact) {
io.swagger.v3.oas.models.info.Contact swaggerContact = new io.swagger.v3.oas.models.info.Contact();
return swaggerContact.name(contact.getName()).email(contact.getEmail()).url(contact.getUrl());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.berkleytechnologyservices.restdocs.spec.generator.openapi_v3;

import com.berkleytechnologyservices.restdocs.spec.ApiDetails;
import com.berkleytechnologyservices.restdocs.spec.Contact;
import com.berkleytechnologyservices.restdocs.spec.Specification;
import com.berkleytechnologyservices.restdocs.spec.generator.SpecificationGeneratorException;
import com.epages.restdocs.apispec.model.HTTPMethod;
Expand Down Expand Up @@ -49,6 +50,21 @@ public void testGenerateHostWithPort() throws SpecificationGeneratorException {
.isEqualToNormalizingNewlines(contentOfResource("/mock-specs/openapi3/host-with-port.yml"));
}

@Test
public void testGenerateContact() throws SpecificationGeneratorException {
Contact contact = new Contact();
contact.setName("John Doe");
contact.setEmail("[email protected]");
contact.setUrl("https://john.example.com");

ApiDetails apiDetails = new ApiDetails().contact(contact);

String rawOutput = generator.generate(apiDetails, list(getMockResource()));

assertThat(rawOutput)
.isEqualToNormalizingNewlines(contentOfResource("/mock-specs/openapi3/contact.yml"));
}

private ResourceModel getMockResource() {
return resource(
"book-get",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ paths:
description: ""
examples: {}
schema:
$ref: '#/definitions/book_id-1050330160'
$ref: '#/definitions/book_id-1528421121'
definitions:
book_id-1050330160:
book_id-1528421121:
type: object
required:
- author
- pages
- title
properties:
pages:
type: number
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
openapi: 3.0.1
info:
title: API Documentation
contact:
name: John Doe
url: https://john.example.com
email: [email protected]
version: 1.0.0
servers:
- url: http://localhost
tags: []
paths:
/book/{id}:
get:
tags:
- book
summary: Get a book by id
description: Get a book by id
operationId: book-get
parameters:
- name: id
in: path
description: The unique identifier for the book.
required: true
schema:
type: number
responses:
"200":
description: "200"
content:
application/hal+json:
schema:
$ref: '#/components/schemas/MyCustomSchemaName'
examples:
book-get:
value: The example response.
components:
schemas:
MyCustomSchemaName:
title: MyCustomSchemaName
required:
- author
- pages
- title
type: object
properties:
pages:
type: number
description: Number of pages in the book
author:
type: string
description: Author of the book
title:
type: string
description: Title of the book
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ components:
schemas:
MyCustomSchemaName:
title: MyCustomSchemaName
required:
- author
- pages
- title
type: object
properties:
pages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ components:
schemas:
MyCustomSchemaName:
title: MyCustomSchemaName
required:
- author
- pages
- title
type: object
properties:
pages:
Expand Down
62 changes: 62 additions & 0 deletions restdocs-spec-maven-plugin/src/it/openapi-3.0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.berkleytechnologyservices.restdocs-spec.it</groupId>
<artifactId>default-settings-it</artifactId>
<version>1.0-SNAPSHOT</version>

<description>Verify the default settings.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/target/generated-snippets</outputDirectory>
<resources>
<resource>
<directory>snippets</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specification>OPENAPI_V3</specification>
<contact>
<name>John Doe</name>
<email>[email protected]</email>
<url>https://john.example.com</url>
</contact>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"operationId" : "cart-add-product",
"summary" : "Add products to a cart",
"description" : "Add products to a cart",
"privateResource" : false,
"deprecated" : false,
"request" : {
"path" : "/carts/{id}/products",
"method" : "POST",
"contentType" : "text/uri-list",
"headers" : [ ],
"pathParameters" : [ ],
"queryParameters" : [ ],
"formParameters" : [ ],
"requestFields" : [ ],
"example" : "http://localhost/products/1",
"securityRequirements" : null
},
"response" : {
"status" : 200,
"contentType" : "application/hal+json",
"headers" : [ ],
"responseFields" : [ ],
"example" : "{\r\n \"total\" : 49.99,\r\n \"products\" : [ {\r\n \"quantity\" : 1,\r\n \"product\" : {\r\n \"name\" : \"Fancy pants\",\r\n \"price\" : 49.99\r\n },\r\n \"_links\" : {\r\n \"product\" : {\r\n \"href\" : \"http://localhost:8080/products/1\"\r\n }\r\n }\r\n } ],\r\n \"_links\" : {\r\n \"self\" : {\r\n \"href\" : \"http://localhost:8080/carts/1\"\r\n },\r\n \"order\" : {\r\n \"href\" : \"http://localhost:8080/carts/1/order\"\r\n }\r\n }\r\n}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"operationId" : "cart-get",
"summary" : "Get a cart by id",
"description" : "Get a cart by id",
"privateResource" : false,
"deprecated" : false,
"request" : {
"path" : "/carts/{id}",
"method" : "GET",
"contentType" : null,
"headers" : [ ],
"pathParameters" : [ {
"name" : "id",
"description" : "the cart id",
"ignored" : false,
"type" : "STRING",
"optional" : false
} ],
"queryParameters" : [ ],
"formParameters" : [ ],
"requestFields" : [ ],
"example" : null,
"securityRequirements" : null
},
"response" : {
"status" : 200,
"contentType" : "application/hal+json",
"headers" : [ ],
"responseFields" : [ {
"description" : "Total amount of the cart.",
"ignored" : false,
"path" : "total",
"type" : "NUMBER",
"optional" : false
}, {
"description" : "The product line item of the cart.",
"ignored" : false,
"path" : "products",
"type" : "ARRAY",
"optional" : false
}, {
"description" : "Link to the product.",
"ignored" : false,
"path" : "products[]._links.product",
"type" : "OBJECT",
"optional" : false
}, {
"description" : "The quantity of the line item.",
"ignored" : false,
"path" : "products[].quantity",
"type" : "NUMBER",
"optional" : false
}, {
"description" : "The product the line item relates to.",
"ignored" : false,
"path" : "products[].product",
"type" : "OBJECT",
"optional" : false
}, {
"description" : "Links section.",
"ignored" : false,
"path" : "_links",
"type" : "OBJECT",
"optional" : false
} ],
"example" : "{\r\n \"total\" : 49.99,\r\n \"products\" : [ {\r\n \"quantity\" : 1,\r\n \"product\" : {\r\n \"name\" : \"Fancy pants\",\r\n \"price\" : 49.99\r\n },\r\n \"_links\" : {\r\n \"product\" : {\r\n \"href\" : \"http://localhost:8080/products/2\"\r\n }\r\n }\r\n } ],\r\n \"_links\" : {\r\n \"self\" : {\r\n \"href\" : \"http://localhost:8080/carts/2\"\r\n },\r\n \"order\" : {\r\n \"href\" : \"http://localhost:8080/carts/2/order\"\r\n }\r\n }\r\n}"
}
}
Loading

0 comments on commit f56a4d5

Please sign in to comment.