Commit 2b5842f0 authored by couzinie's avatar couzinie
Browse files

Added import JSON

parent fdc5e743
"use strict";
export enum HttpMethod {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
PATCH = 'PATCH',
DELETE = 'DELETE',
HEAD = 'HEAD',
OPTIONS = 'OPTIONS'
GET = 'get',
POST = 'post',
PUT = 'put',
PATCH = 'patch',
DELETE = 'delete',
HEAD = 'head',
OPTIONS = 'options'
}
......
......@@ -14,7 +14,8 @@ export interface SchemaDTO {
export interface ParameterDTO {
in: ParameterType,
name: string,
schema: SchemaDTO
schema: SchemaDTO,
required: boolean
}
export interface ItemDTO {
......@@ -42,7 +43,7 @@ export interface RequestDTO {
description: string,
tags: string[]
parameters: ParameterDTO[],
responses : HttpCodeToResponseMapDTO[],
responses : HttpCodeToResponseMapDTO,
}
export type MethodToRequestMapDTO = Map<HttpMethod,RequestDTO>;
......
......@@ -13,7 +13,8 @@ export interface Schema {
export interface Parameter {
in: ParameterType,
name: string,
schema: Schema
schema: Schema,
required: boolean
}
export interface Item {
......
......@@ -106,13 +106,13 @@
<tr>
<td>
<nb-select [(ngModel)]="request.httpmethod">
<nb-option value="GET">GET</nb-option>
<nb-option value="POST">POST</nb-option>
<nb-option value="PUT">PUT</nb-option>
<nb-option value="PATCH">PATCH</nb-option>
<nb-option value="DELETE">DELETE</nb-option>
<nb-option value="HEAD">HEAD</nb-option>
<nb-option value="OPTIONS">OPTIONS</nb-option>
<nb-option value="get">GET</nb-option>
<nb-option value="post">POST</nb-option>
<nb-option value="put">PUT</nb-option>
<nb-option value="patch">PATCH</nb-option>
<nb-option value="delete">DELETE</nb-option>
<nb-option value="head">HEAD</nb-option>
<nb-option value="options">OPTIONS</nb-option>
</nb-select>
</td>
<td>
......@@ -219,11 +219,13 @@
</nb-card>
</div>
</nb-tab>
<nb-tab class="repository" tabTitle="EXPORT JSON" tabIcon="file-text-outline">
<nb-tab class="json" tabTitle="JSON" tabIcon="file-text-outline">
<nb-card>
<nb-card-body>
<button nbButton type="button" (click)="selectAllJson()"><nb-icon icon="copy-outline"></nb-icon>Select all</button>
<button nbButton type="button" (click)="downloadJson()"><nb-icon icon="download-outline"></nb-icon>Download</button>
<button nbButton type="button" (click)="openFileInputDialog()"><nb-icon icon="upload-outline"></nb-icon>Import</button>
<input id="jsonfileinput" type="file" (change)="importJson($event)" />
<pre id="json">{{getPrettyJson()}}</pre>
</nb-card-body>
</nb-card>
......
......@@ -63,3 +63,24 @@ MAIN TAB
.main div.request span.title {
margin-right: 0.32em;
}
/**
JSON TAB
*/
#jsonfileinput {
display: none;
}
.json button{
margin: 0.32em;
}
/**
SWAGGER TAB
*/
#swaggereditor{
height: 600px;
position: relative;
}
\ No newline at end of file
......@@ -119,6 +119,23 @@ export class PublishApiComponent implements OnInit {
}
}
openFileInputDialog(): void {
document.getElementById('jsonfileinput').click();
}
importJson(event:Event): void {
const files: FileList = (event.target as HTMLInputElement).files;
const jsonFile: File = files[0];
var reader = new FileReader();
reader.onload = ()=> {
console.log(reader.result as string);
this.openApi = this.openApiService.getFromString(reader.result as string);
};
reader.readAsText(jsonFile);
}
goToLink() {
window.open("/swaggerapi");
}
......
......@@ -19,7 +19,7 @@ export class OpenApiDTOMappingService {
return content;
}
mapResponseFromDTO(httpCodeToResponseMapDTO: HttpCodeToResponseMapDTO[], httpStatusCodeToreponseDTOMap: string): Response {
mapResponseFromDTO(httpCodeToResponseMapDTO: HttpCodeToResponseMapDTO, httpStatusCodeToreponseDTOMap: string): Response {
let responseDTO: ResponseDTO = httpCodeToResponseMapDTO[httpStatusCodeToreponseDTOMap];
let response: Response = {} as Response;
response.description = responseDTO.description;
......@@ -82,9 +82,9 @@ export class OpenApiDTOMappingService {
*/
mapToDto(openApi:OpenApi): OpenApiDTO {
let openApiDTO:OpenApiDTO = {} as OpenApiDTO;
openApiDTO.openapi = openApi.openapi;
openApiDTO.info = openApi.info as InfoMapDTO;
openApiDTO.servers = openApi.servers as ServerDTO[];
openApiDTO.openapi = openApi.openapi;
openApiDTO.paths = new Map<string,MethodToRequestMapDTO>();
openApi.paths.forEach(path=>{
let methodToRequestMapDTO: MethodToRequestMapDTO = new Map<HttpMethod, RequestDTO>();
......@@ -93,18 +93,19 @@ export class OpenApiDTOMappingService {
requestDTO.tags = request.tags;
requestDTO.description = request.description;
requestDTO.parameters = request.parameters as ParameterDTO[];
requestDTO.responses = [] as HttpCodeToResponseMapDTO[];
requestDTO.responses = {} as HttpCodeToResponseMapDTO;
request.responses.forEach(response=>{
let httpCodeToResponseMapDTO: HttpCodeToResponseMapDTO = new Map<HttpStatusCode, ResponseDTO>();
let responseDTO: ResponseDTO = {} as ResponseDTO;
responseDTO.content = new Map<string, ContentDTO>();
responseDTO.description = response.description;
response.contents.forEach(content=>{
let contentDTO: ContentDTO = {} as ContentDTO;
contentDTO.schema = content.schema as ResponseSchemaDTO;
responseDTO.content.set(content.contentType, contentDTO);
});
httpCodeToResponseMapDTO.set(response.httpStatusCode,responseDTO);
requestDTO.responses.push(httpCodeToResponseMapDTO);
requestDTO.responses=httpCodeToResponseMapDTO;
});
methodToRequestMapDTO.set(request.httpmethod, requestDTO);
});
......
......@@ -43,6 +43,11 @@ export class OpenApiService {
return this.openApiDTOMappingService.mapOpenApiFromDTO(openApiDTO);
}
getFromString(json: string): OpenApi {
let openApiDTO:OpenApiDTO = <OpenApiDTO>JSON.parse(json);
return this.openApiDTOMappingService.mapOpenApiFromDTO(openApiDTO);
}
getEmptyPath(): Path {
let pathDTO: PathMapDTO = <PathMapDTO>JSON.parse(this.emptyPathJson);
let paths = [] as Path[];
......@@ -69,7 +74,7 @@ export class OpenApiService {
}
getEmptyResponse(): Response {
let httpCodeToResponseMapDTO : HttpCodeToResponseMapDTO[] = <HttpCodeToResponseMapDTO[]>JSON.parse('{' + this.emptyResponse + '}');
let httpCodeToResponseMapDTO : HttpCodeToResponseMapDTO = <HttpCodeToResponseMapDTO>JSON.parse('{' + this.emptyResponse + '}');
let responses = [] as Response[];
Object.keys(httpCodeToResponseMapDTO).forEach((httpStatusCode:string)=>{
let response: Response = this.openApiDTOMappingService.mapResponseFromDTO(httpCodeToResponseMapDTO, httpStatusCode);
......@@ -97,7 +102,7 @@ export class OpenApiService {
' ],' +
' "paths" : {' +
' "/search" : {' +
' "GET" : {' +
' "get" : {' +
' "description" : "Returns a list of datasets",' +
' "tags" : [ ' +
' "datasetlist"' +
......@@ -110,6 +115,7 @@ export class OpenApiService {
' "type" : "string",' +
' "default" : "*"' +
' },' +
' "required" : true,' +
' "description" : "for all star"' +
' }, ' +
' {' +
......@@ -119,6 +125,7 @@ export class OpenApiService {
' "type" : "integer",' +
' "default" : 10' +
' },' +
' "required" : true,' +
' "description" : "pages"' +
' }, ' +
' {' +
......@@ -128,6 +135,7 @@ export class OpenApiService {
' "type" : "string",' +
' "default" : "dataset"' +
' },' +
' "required" : true,' +
' "description" : "dataset"' +
' }, ' +
' {' +
......@@ -137,6 +145,7 @@ export class OpenApiService {
' "type" : "integer",' +
' "default" : 0' +
' },' +
' "required" : true,' +
' "description" : "start"' +
' }, ' +
' {' +
......@@ -146,6 +155,7 @@ export class OpenApiService {
' "type" : "boolean",' +
' "default" : true' +
' },' +
' "required" : true,' +
' "description" : "id"' +
' }, ' +
' {' +
......@@ -155,6 +165,7 @@ export class OpenApiService {
' "type" : "boolean",' +
' "default" : true' +
' },' +
' "required" : true,' +
' "description" : "aaa"' +
' }' +
' ],' +
......@@ -176,7 +187,7 @@ export class OpenApiService {
' }' +
' },' +
' "/datasets/{entity_id}" : {' +
' "GET" : {' +
' "get" : {' +
' "description" : "Get the details on the dataset that the identifier is in parameter ",' +
' "tags" : [ ' +
' "dataset"' +
......@@ -189,6 +200,7 @@ export class OpenApiService {
' "type" : "string",' +
' "default" : "95707"' +
' },' +
' "required" : true,' +
' "description" : "he Digital Object Identifier (DOI) of the dataset searched."' +
' }' +
' ],' +
......@@ -231,7 +243,7 @@ export class OpenApiService {
' ],' +
' "paths" : {' +
' " " : {' +
' "GET" : {' +
' "get" : {' +
' "description" : "",' +
' "tags" : [ ' +
' "datasetlist"' +
......@@ -265,7 +277,7 @@ export class OpenApiService {
' }' +
' },' +
' " " : {' +
' "GET" : {' +
' "get" : {' +
' "description" : "",' +
' "tags" : [ ' +
' "dataset"' +
......@@ -325,12 +337,14 @@ export class OpenApiService {
' "type" : "string",' +
' "default" : ""' +
' }' +
' "required" : true,' +
' "description" : ""' +
' }' +
']';
private emptyMethodJson =
' "GET" : {' +
' "get" : {' +
' "description" : "",' +
' "tags" : [ ' +
' "datasetlist"' +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment