Skip to content

Commit

Permalink
Merge pull request #31 from christiemolloy/iss-28
Browse files Browse the repository at this point in the history
Add Create API
  • Loading branch information
jenny-s51 authored Jun 19, 2020
2 parents 756a7fb + c3959bf commit 5d14c71
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 121 deletions.
100 changes: 53 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"axios": "^0.19.2",
"babel-preset-es2015": "^6.24.1",
"js-base64": "2.5.2",
"moment": "^2.24.0",
"prop-types": "^15.7.2",
"react": "^16.13.1",
Expand Down
32 changes: 32 additions & 0 deletions packages/models/src/create-api-form-data.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2017 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {ApiDesignTemplate} from './api-design-template.model';

export class CreateApiFormData {

type: string;
name: string;
description: string;
template?: ApiDesignTemplate

constructor() {
this.type = "OpenAPI30";
this.name = null;
this.description = null;
this.template = null
}
}
1 change: 1 addition & 0 deletions packages/models/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './bitbucket-team.model';
export * from './codegen-project.model';
export * from './complete-linked-account.model';
export * from './create-linked-account.model';
export * from './create-api-form-data.model';
export * from './deferred.model';
export * from './editor-user.model';
export * from './github-organization.model';
Expand Down
4 changes: 2 additions & 2 deletions packages/models/src/new-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

export class NewApi {

specVersion: string;
type: string;
name: string;
description: string;

constructor() {
this.specVersion = null;
this.type = null;
this.name = "";
this.description = "";
}
Expand Down
26 changes: 20 additions & 6 deletions packages/services/src/api-services/api-services.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Api, ApiCollaborator} from "@apicurio/models";
import {Api, NewApi, ImportApi, ApiCollaborator} from "@apicurio/models";
import {AbstractHubService} from "./hub";
import {ConfigService} from "../config/config.service";
import {IAuthenticationService} from "../authentication/auth.service";
Expand All @@ -12,15 +12,29 @@ export class ApisService extends AbstractHubService {
private cachedApis: Api[] = null;
private cachedCollaborators: ApiCollaborator[] = null;

/**
* Constructor.
* @param authService
* @param config
*/
constructor(authService: IAuthenticationService, config: ConfigService) {
super(authService, config);
}

public createApi(api: NewApi): Promise<Api> {
console.info("[ApisService] Creating the API via the hub API");

const createApiUrl: string = this.endpoint("designs");
const options: AxiosRequestConfig = this.options({ "Accept": "application/json", "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" });

console.info("[ApisService] Creating an API Design: %s", createApiUrl);
return this.httpPostWithReturn<NewApi, Api>(createApiUrl, api, options);
}

public importApi(api: ImportApi): Promise<Api> {
console.info("[ApisService] Importing an API design via the hub API");

const importApiUrl: string = this.endpoint("designs");
const options: AxiosRequestConfig = this.options({ "Accept": "application/json", "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" });

console.info("[ApisService] Importing an API Design: %s", importApiUrl);
return this.httpPutWithReturn<ImportApi, Api>(importApiUrl, api, options);
}
/**
* @see ApisService.getCollaborators
*/
Expand Down
Loading

0 comments on commit 5d14c71

Please sign in to comment.