Skip to content

Commit

Permalink
#657 initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Aug 8, 2019
1 parent 8b37a84 commit e2c7d59
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ dependencies {
}

implementation "org.joda:joda-money:1.0.1"

testImplementation "de.codecentric.hikaku:hikaku-openapi:2.3.0"
testImplementation "de.codecentric.hikaku:hikaku-spring:2.3.0"
}

// -- license configuration
Expand Down
124 changes: 124 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"openapi": "3.0.1",
"info": {
"title": "Alf.io api",
"version": "2.0.0"
},
"paths": {
"/pet": {
"put": {
"summary": "Update an existing pet",
"operationId": "updatePet",
"requestBody": {
"description": "Pet object that needs to be added to the store",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
},
"required": true
},
"responses": {
"400": {
"description": "Invalid ID supplied",
"content": {}
},
"404": {
"description": "Pet not found",
"content": {}
},
"405": {
"description": "Validation exception",
"content": {}
}
}
}
}
},
"components": {
"schemas": {
"Category": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
},
"Pet": {
"required": [
"name",
"photoUrls"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"category": {
"$ref": "#/components/schemas/Category"
},
"name": {
"type": "string",
"example": "doggie"
},
"photoUrls": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Tag"
}
},
"status": {
"type": "string",
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
]
}
}
},
"ApiResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"type": {
"type": "string"
},
"message": {
"type": "string"
}
}
}
}
}
}
85 changes: 85 additions & 0 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# use https://editor.swagger.io/ , edit, generate json
openapi: 3.0.1
info:
title: Alf.io api
version: 2.0.0
paths:
/pet:
put:
summary: Update an existing pet
operationId: updatePet
requestBody:
description: Pet object that needs to be added to the store
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
required: true
responses:
400:
description: Invalid ID supplied
content: {}
404:
description: Pet not found
content: {}
405:
description: Validation exception
content: {}
components:
schemas:
Category:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
Tag:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
Pet:
required:
- name
- photoUrls
type: object
properties:
id:
type: integer
format: int64
category:
$ref: '#/components/schemas/Category'
name:
type: string
example: doggie
photoUrls:
type: array
items:
type: string
tags:
type: array
items:
$ref: '#/components/schemas/Tag'
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
ApiResponse:
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string

55 changes: 55 additions & 0 deletions src/test/java/alfio/controller/api/CheckApiConformanceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package alfio.controller.api;

import alfio.TestConfiguration;
import alfio.config.DataSourceConfiguration;
import alfio.config.Initializer;
import alfio.config.MvcConfiguration;
import alfio.util.BaseIntegrationTest;
import de.codecentric.hikaku.Hikaku;
import de.codecentric.hikaku.HikakuConfig;
import de.codecentric.hikaku.converters.openapi.OpenApiConverter;
import de.codecentric.hikaku.converters.spring.SpringConverter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.transaction.annotation.Transactional;

import java.nio.file.Paths;
import java.util.Set;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {DataSourceConfiguration.class, TestConfiguration.class, MvcConfiguration.class})
@ActiveProfiles({Initializer.PROFILE_DEV, Initializer.PROFILE_DISABLE_JOBS, Initializer.PROFILE_INTEGRATION_TEST})
@Transactional
@WebAppConfiguration
public class CheckApiConformanceTest extends BaseIntegrationTest {


@Autowired
private ApplicationContext springContext;

@Test
public void specificationMatchesImplementation() {
OpenApiConverter specification = new OpenApiConverter(Paths.get("docs/openapi.json"));
SpringConverter implementation = new SpringConverter(springContext);

HikakuConfig hikakuConfig = new HikakuConfig(
Set.of("/healthz", "/", "/admin", "/file/{digest}", "/report-csp-violation"),
//Set.of("/admin/api/", "/api/payment/*"),
true,
true
);

/*new Hikaku(
specification,
implementation,
hikakuConfig
).match();*/
}

}

0 comments on commit e2c7d59

Please sign in to comment.