Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Create API #31

Merged
merged 12 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do a find/replace from 2017 to 2020 on all these files. Or else remove the license entirely if we don't need it. I'm never sure. Either way, not something to change for this PR...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! i created this issue to track it: #37

*
* 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";
dlabaj marked this conversation as resolved.
Show resolved Hide resolved
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": "*" });
dlabaj marked this conversation as resolved.
Show resolved Hide resolved

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