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 10 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
56 changes: 21 additions & 35 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",
dlabaj marked this conversation as resolved.
Show resolved Hide resolved
"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
48 changes: 48 additions & 0 deletions packages/services/src/api-services/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,53 @@ export abstract class AbstractHubService {
})
.catch(error => console.log(error)); // handle error state
}

// (createApiUrl, api, options);
protected httpPostWithReturn<I, O>(url: string, data: I, options: AxiosRequestConfig, successCallback?: (data: any) => any): Promise<O> {

const stringify = JSON.stringify(data);
const config: AxiosRequestConfig = {...{
method: 'post',
url: url,
data: stringify
}, ...options}

console.log('did it make it to the post');
Copy link
Member

Choose a reason for hiding this comment

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

Debug statement still needed?


return axios.request(config)
.then(response => {
let data = response;
console.log('what is the response' + data)
Copy link
Member

Choose a reason for hiding this comment

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

Remove this before checkin/merge?

if(successCallback) {
return successCallback(data);
}
else {
return data;
}
})
.catch(error => console.log(error));
}

protected httpPutWithReturn<I, O>(url: string, data: I, options: any, successCallback?: (data: any) => any): Promise<O> {

const stringify = JSON.stringify(data);
const config: AxiosRequestConfig = {...{
method: 'put',
url: url,
data: stringify
}, ...options}

return axios.request(config)
.then(response => {
let data = response;
if(successCallback) {
return successCallback(data);
}
else {
return response;
}
})
.catch(error => console.log(error));
}

}
13 changes: 0 additions & 13 deletions packages/studio/src/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,6 @@
color: var(--pf-global--Color--100);
}

.app-create-api-form {
width: 50%;
}

.app-form-helper-text {
font-size: var(--pf-global--FontSize--sm);
color: var(--pf-global--Color--200);
}

.app-form-helper-text-asterisk {
color: var(--pf-global--danger-color--100);
}

.app-import-api-split-layout > .pf-l-split__item {
width: 50%;
margin-right: var(--pf-global--spacer--xl);
Expand Down
7 changes: 6 additions & 1 deletion packages/studio/src/app/common/appConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {ApisService, CurrentUserService, KeycloakAuthenticationService, ConfigService} from '@apicurio/services';
import {
ApisService,
CurrentUserService,
KeycloakAuthenticationService,
ConfigService
} from '@apicurio/services';

// Initialize services.

Expand Down
57 changes: 57 additions & 0 deletions packages/studio/src/app/pages/api/createApi.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.app-create-api__form-card-text span {
margin-left: var(--pf-global--spacer--sm);
}

.app-create-api__form-card {
box-shadow: none !important;
}

.app-create-api__form-card:hover {
box-shadow: none !important;
color: var(--pf-global--primary-color--100);
}


.app-create-api__form-card::after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
content: "";
border: var(--pf-global--BorderWidth--sm) solid var(--pf-global--BorderColor--100);
}

.app-create-api__form-card:hover::after {
border-color: var(--pf-global--primary-color--100);
}

.app-create-api__form-card-group {
display: grid;
grid-column-gap: var(--pf-global--spacer--sm);
grid-template-columns: 1fr 1fr 1fr;
}

.app-create-api__form {
width: 100%;
}

@media screen and (min-width: 768px) {
.app-create-api__form {
width: 50%;
}
}

.app-form-helper-text {
font-size: var(--pf-global--FontSize--sm);
color: var(--pf-global--Color--200);
}

.app-form-helper-text-asterisk {
color: var(--pf-global--danger-color--100);
}

.app-form-helper-text span {
margin-left: 0 !important;
padding-bottom: 0 !important;
}
Loading