Skip to content

Commit

Permalink
Added check if subscription is required for API when displaying API c…
Browse files Browse the repository at this point in the history
…onsole. Added more jsdocs to API contract and model. Fixed the way binary files get sent. (#797)
  • Loading branch information
azaslonov authored Jul 30, 2020
1 parent 79672ec commit 1b2ff7e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ <h3>Authorization</h3>
</div>
<!-- /ko -->

<!-- ko if: $component.subscriptionKeyRequired -->
<div class="row flex flex-row">
<div class="col-4">
<label for="subscriptionKey" class="text-monospace form-label">
Expand All @@ -113,6 +114,7 @@ <h3>Authorization</h3>
</div>
</div>
</div>
<!-- /ko -->

<h3>Parameters</h3>
<!-- ko if: (templateParameters && templateParameters().length > 0) || (request.queryParameters && request.queryParameters().length > 0) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class OperationConsole {
public readonly responseHeadersString: ko.Observable<string>;
public readonly products: ko.Observable<Product[]>;
public readonly selectedSubscriptionKey: ko.Observable<string>;
public readonly subscriptionKeyRequired: ko.Observable<boolean>;
public readonly selectedLanguage: ko.Observable<string>;
public readonly selectedProduct: ko.Observable<Product>;
public readonly requestError: ko.Observable<string>;
Expand Down Expand Up @@ -84,6 +85,7 @@ export class OperationConsole {
this.consoleOperation = ko.observable();
this.secretsRevealed = ko.observable();
this.selectedSubscriptionKey = ko.observable();
this.subscriptionKeyRequired = ko.observable();
this.working = ko.observable(true);
this.sendingRequest = ko.observable(false);
this.codeSample = ko.observable();
Expand Down Expand Up @@ -165,6 +167,7 @@ export class OperationConsole {
this.responseStatusText(null);
this.responseBody(null);
this.selectedSubscriptionKey(null);
this.subscriptionKeyRequired(!!selectedApi.subscriptionRequired);
this.selectedProduct(null);

const operation = await this.apiService.getOperation(selectedOperation.id);
Expand Down Expand Up @@ -193,7 +196,10 @@ export class OperationConsole {
}

await this.setupOAuth();
await this.loadSubscriptionKeys();

if (selectedApi.subscriptionRequired) {
await this.loadSubscriptionKeys();
}

this.updateRequestSummary();
this.working(false);
Expand Down Expand Up @@ -443,9 +449,7 @@ export class OperationConsole {
break;

case "binary":
const formData = new FormData();
formData.append(request.binary().name, request.binary());
payload = formData;
payload = await Utils.readFileAsByteArray(request.binary());
break;

default:
Expand Down
72 changes: 66 additions & 6 deletions src/contracts/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { OperationContract } from "./operation";
import { AuthenticationSettings } from "./authenticationSettings";
import { ArmResource } from "./armResource";

Expand All @@ -10,32 +9,93 @@ export interface ApiContract extends ArmResource {
}

export interface ApiProperties {
/**
* API name. Must be 1 to 300 characters long.
*/
displayName?: string;

/**
* Description of the API. May include HTML formatting tags.
*/
description?: string;

/**
* Indicates the Version identifier of the API if the API is versioned.
*/
apiVersion?: string;

/**
* Description of the API Version.
*/
apiVersionDescription?: string;

/**
* A resource identifier for the related API version set.
*/
apiVersionSetId?: string;

/**
* Version set details.
*/
apiVersionSet?: {
name: string,
description: string,
versioningScheme: string,
versionQueryName: string,
versionHeaderName: string
};

/**
* Describes the Revision of the Api. If no value is provided, default revision 1 is created.
*/
apiRevision?: string;

/**
* Description of the Api Revision.
*/
apiRevisionDescription?: string;

/**
* Absolute URL of the backend service implementing this API. Cannot be more than 2000 characters long.
*/
serviceUrl?: string;

/**
* Relative URL uniquely identifying this API and all of its resource paths within the API Management
* service instance. It is appended to the API endpoint base URL specified during the service instance
* creation to form a public URL for this API.
*/
path?: string;

/**
* Describes on which protocols the operations in this API can be invoked.
*/
protocols?: string[];
proxyAuth?: string;

/**
* API Authentication Settings.
*/
authenticationSettings?: AuthenticationSettings;

/**
* Subscription key parameter names details.
*/
subscriptionKeyParameterNames?: SubscriptionKeyParameterName;
urlSuffix?: string;
operations?: OperationContract[];

/**
* Type of API, e.g. "http" or "soap".
*/
type?: string;

/**
* Indicates if API revision is current api revision.
*/
isCurrent?: boolean;
isOnline?: boolean;
subscriptionRequired?: boolean;

/**
* Specifies whether an API or Product subscription is required for accessing the API.
*/
subscriptionRequired: boolean;
}


Expand Down
1 change: 0 additions & 1 deletion src/contracts/authenticationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ export interface OpenIdAuthenticationSettings {
export interface AuthenticationSettings {
oAuth2?: OAuth2AuthenticationSettings;
openid?: OpenIdAuthenticationSettings;
subscriptionKeyRequired?: boolean;
}
18 changes: 15 additions & 3 deletions src/models/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class Api {
*/
public displayName?: string;

/**
* Display name of API that includes version.
*/
public versionedDisplayName?: string;

/**
Expand Down Expand Up @@ -74,17 +77,26 @@ export class Api {
*/
public protocols?: string[];

/**
* Subscription key parameter names details.
*/
public subscriptionKeyParameterNames?: SubscriptionKeyParameterName;

public urlSuffix?: string;

/**
* Determines type of API, e.g. "soap".
*/
public type?: string;

/**
* Information about associated authorization servers (OAuth 2 or OpenID Connect).
*/
public authenticationSettings: AuthenticationSettings;

/**
* Specifies whether an API or Product subscription is required for accessing the API.
*/
public subscriptionRequired: boolean;

constructor(contract?: ApiContract) {
if (contract.id) {
this.id = Utils.getResourceName("apis", contract.id, "shortId");
Expand All @@ -98,12 +110,12 @@ export class Api {
this.description = contract.properties.description;
this.path = contract.properties.path;
this.versionedPath = this.path;
this.urlSuffix = contract.properties.urlSuffix;
this.apiVersion = contract.properties.apiVersion;
this.apiRevision = contract.properties.apiRevision;
this.subscriptionKeyParameterNames = contract.properties.subscriptionKeyParameterNames;
this.type = contract.properties.type;
this.authenticationSettings = contract.properties.authenticationSettings;
this.subscriptionRequired = contract.properties.subscriptionRequired;

if (contract.properties.apiVersionSet) {
const nestedVersionSet = contract.properties.apiVersionSet;
Expand Down
12 changes: 12 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,16 @@ export class Utils {

return utc;
}

public static readFileAsByteArray(file: File): Promise<Uint8Array> {
return new Promise<Uint8Array>(resolve => {
const reader = new FileReader();

reader.onload = (event: any) => {
resolve(event.target.result);
};

reader.readAsArrayBuffer(file);
});
}
}

0 comments on commit 1b2ff7e

Please sign in to comment.