Skip to content

Commit

Permalink
Added basic XSD schema support in API documentation. (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov authored Jan 29, 2021
1 parent 90ab863 commit 8ca00a5
Show file tree
Hide file tree
Showing 14 changed files with 761 additions and 63 deletions.
7 changes: 6 additions & 1 deletion 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 @@ -89,6 +89,7 @@
"prismjs": "^1.22.0",
"remark": "^13.0.0",
"remark-html": "^13.0.1",
"saxen": "^8.1.2",
"slick": "^1.12.2",
"topojson-client": "^3.1.0",
"truncate-html": "^1.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export class OperationDetails {
return;
}

if (!operationName) {
this.selectedOperationName(null);
if (!operationName) {
this.selectedOperationName(null);
this.operation(null);
return;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ export class OperationDetails {
}
}

this.definitions(definitions.filter(d => typeNames.indexOf(d.name) !== -1));
this.definitions(definitions.filter(definition => typeNames.indexOf(definition.name) !== -1));
}

private lookupReferences(definitions: TypeDefinition[], skipNames: string[]): string[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@

<!-- ko if: $component.example -->
<h5>Example</h5>
<code-sample params="{ content: $component.example, language: $component.exampleLanguage }"></code-sample>
<code-sample params="{ content: $component.example, language: $component.exampleFormat }"></code-sample>
<!-- /ko -->
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h4 class="text-truncate flex-grow" data-bind="text: $component.name"></h4>
</ul>

<!-- ko if: schemaView() == 'raw' -->
<code-sample params="{ content: $component.schemaObject, language: 'json' }"></code-sample>
<code-sample params="{ content: $component.rawSchema, language: $component.rawSchemaFormat }"></code-sample>
<!-- /ko -->

<!-- ko if: schemaView() == 'table' -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ export class TypeDefinitionViewModel {
public readonly description: ko.Observable<string>;
public readonly kind: ko.Observable<string>;
public readonly example: ko.Observable<string>;
public readonly exampleLanguage: ko.Observable<string>;
public readonly schemaObject: ko.Observable<string>;
public readonly exampleFormat: ko.Observable<string>;
public readonly rawSchema: ko.Observable<string>;
public readonly rawSchemaFormat: ko.Observable<string>;
public readonly schemaView: ko.Observable<string>;

constructor(private readonly routeHelper: RouteHelper) {
this.name = ko.observable();
this.schemaObject = ko.observable();
this.description = ko.observable();
this.kind = ko.observable();
this.example = ko.observable();
this.exampleLanguage = ko.observable();
this.exampleFormat = ko.observable();
this.rawSchema = ko.observable();
this.rawSchemaFormat = ko.observable();
this.schemaView = ko.observable();
this.defaultSchemaView = ko.observable();
}
Expand All @@ -54,13 +56,15 @@ export class TypeDefinitionViewModel {
@OnMounted()
public initialize(): void {
this.schemaView(this.defaultSchemaView() || "table");
this.schemaObject(JSON.stringify(this.definition.schemaObject, null, 4));
this.rawSchema(this.definition.rawSchema);
this.rawSchemaFormat(this.definition.rawSchemaFormat);

this.name(this.definition.name);
this.description(this.definition.description);
this.kind(this.definition.kind);

if (this.definition.example) {
this.exampleLanguage(this.definition.exampleFormat);
this.exampleFormat(this.definition.exampleFormat);
this.example(this.definition.example);
}
}
Expand Down
30 changes: 27 additions & 3 deletions src/contracts/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,25 @@ export interface SchemaObjectContract extends ReferenceObjectContract {

minProperties?: number;

/**
* Example of the payload represented by this schema object.
*/
example?: string;

/**
* Format of payload example represented by this schema object. It is used for syntax highlighting.
*/
exampleFormat?: string;

/**
* Raw schema representation.
*/
rawSchema?: string;

/**
* Raw schema format. It is used for syntax highlighting.
*/
rawSchemaFormat?: string;
}

/**
Expand Down Expand Up @@ -124,17 +142,23 @@ export interface OpenApiSchemaContract {
};
}

export interface XsdSchemaContract {
value: string;
}


/**
*
*/
export interface SchemaContract extends ArmResource {
export interface SchemaContract extends ArmResource {
properties: {
contentType: string;
document?: SwaggerSchemaContract | OpenApiSchemaContract;
document?: SwaggerSchemaContract | OpenApiSchemaContract | XsdSchemaContract;
};
}

export enum SchemaType {
swagger = "application/vnd.ms-azure-apim.swagger.definitions+json",
openapi = "application/vnd.oai.openapi.components+json"
openapi = "application/vnd.oai.openapi.components+json",
xsd = "application/vnd.ms-azure-apim.xsd+xml"
}
15 changes: 11 additions & 4 deletions src/models/authorizationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export class AuthorizationServer {
? contract.properties.defaultScope.split(" ")
: [];

if (contract.properties.grantTypes) {
this.grantTypes = contract.properties.grantTypes.map(grantType => {
if (!contract.properties.grantTypes) {
return;
}

this.grantTypes = contract.properties.grantTypes
.map(grantType => {
switch (grantType) {
case "authorizationCode":
return "authorization_code";
Expand All @@ -37,8 +41,11 @@ export class AuthorizationServer {
return "client_credentials";
case "resourceOwnerPassword":
return "password";
default:
console.log(`Unsupported grant type ${grantType}`);
return null;
}
});
}
})
.filter(grantType => !!grantType);
}
}
Loading

0 comments on commit 8ca00a5

Please sign in to comment.