mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-24 01:23:43 +03:00
Merge commit 'dd686004766a2cdd54dc733cb4d27b258c055e46' into releases
This commit is contained in:
commit
5c7c28d6d8
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -1,3 +1,22 @@
|
|||
# 1.2.0 (2016-08-30)
|
||||
### Bug fixes
|
||||
* Fix sticky sidebar top sticking (#75)
|
||||
* Fix array inside objects if referenced directly (#84)
|
||||
* Add banner to the bundle file (#89)
|
||||
* Fix broken additionalProperties
|
||||
* Fix version render issue (extra "v" letter)
|
||||
|
||||
### Features/Improvements
|
||||
* Change the way discriminator is rendered
|
||||
* Created CDN major release 1.x.x (#87)
|
||||
* Smaller bundle size (371KB gzipped)
|
||||
* Better start-up time due to [AoT](http://blog.mgechev.com/2016/08/14/ahead-of-time-compilation-angular-offline-precompilation/)
|
||||
|
||||
### Code refactoring
|
||||
* Moved build-system to Webpack
|
||||
* Moved to latest Typescript + get rid of typings
|
||||
* Upgrade to the latest Angular2 RC.5
|
||||
|
||||
# 1.1.2 (2016-08-21)
|
||||
### Bug fixes
|
||||
* Revert "Fix markdown newlines to be GFM" (#82)
|
||||
|
|
|
@ -27,8 +27,9 @@
|
|||
|
||||
## Releases
|
||||
We host latest and all the previous ReDoc releases on GitHub Pages-based **CDN**:
|
||||
- `latest` release: https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js
|
||||
- particular release, e.g. `v0.16.1`: https://rebilly.github.io/ReDoc/releases/v0.16.0/redoc.min.js
|
||||
- particular release, e.g. `v1.2.0`: https://rebilly.github.io/ReDoc/releases/v1.2.0/redoc.min.js
|
||||
- `v1.x.x` release: https://rebilly.github.io/ReDoc/releases/v1.x.x/redoc.min.js
|
||||
- `latest` release: https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js **[not for production]**
|
||||
|
||||
## Deployment
|
||||
|
||||
|
@ -98,6 +99,7 @@ ReDoc makes use of the following [vendor extensions](http://swagger.io/specifica
|
|||
* [`x-logo`](docs/redoc-vendor-extensions.md#x-logo) - is used to specify API logo
|
||||
* [`x-traitTag`](docs/redoc-vendor-extensions.md#x-traitTag) - useful for handling out common things like Pagination, Rate-Limits, etc
|
||||
* [`x-code-samples`](docs/redoc-vendor-extensions.md#x-code-samples) - specify operation code samples
|
||||
* [`x-nullable`](docs/redoc-vendor-extensions.md#nullable) - mark schema param as a nullable
|
||||
|
||||
### `<redoc>` tag attributes
|
||||
* `spec-url` - relative or absolute url to your spec file;
|
||||
|
|
|
@ -819,6 +819,7 @@ definitions:
|
|||
type: string
|
||||
pattern: "^\\+(?:[0-9]-?){6,14}[0-9]$"
|
||||
example: +1-202-555-0192
|
||||
x-nullable: true
|
||||
userStatus:
|
||||
description: User status
|
||||
type: integer
|
||||
|
|
|
@ -106,3 +106,13 @@ yaml
|
|||
lang: JavaScript
|
||||
source: console.log('Hello World');
|
||||
```
|
||||
|
||||
### Schema Object vendor extensions
|
||||
Extends OpenAPI [Schema Object](http://swagger.io/specification/#schemaObject)
|
||||
#### x-code-samples
|
||||
| Field Name | Type | Description |
|
||||
| :------------- | :------: | :---------- |
|
||||
| x-nullable | boolean | marks schema as a nullable |
|
||||
|
||||
###### Usage in ReDoc
|
||||
Schemas marked as `x-nullable` are marked in ReDoc with the label Nullable
|
||||
|
|
|
@ -63,6 +63,14 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.param-nullable {
|
||||
vertical-align: middle;
|
||||
line-height: $param-name-height;
|
||||
color: #3195a6;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.param-type {
|
||||
vertical-align: middle;
|
||||
line-height: $param-name-height;
|
||||
|
|
|
@ -46,7 +46,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
|
|||
}
|
||||
|
||||
load() {
|
||||
if (this.optionsService.options.disableLazySchemas) return;
|
||||
if (this.disableLazy) return;
|
||||
if (this.loaded) return;
|
||||
if (this.pointer) {
|
||||
this._loadAfterSelf();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
title="{{schema._displayTypeHint}}">{{schema._displayType}} {{schema._displayFormat}}
|
||||
<span class="param-range" *ngIf="schema._range"> {{schema._range}} </span>
|
||||
</span>
|
||||
<span *ngIf="schema['x-nullable']" class="param-nullable">Nullable</span>
|
||||
<div *ngIf="schema.enum" class="param-enum">
|
||||
<span *ngFor="let enumItem of schema.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span>
|
||||
</div>
|
||||
|
@ -70,6 +71,7 @@
|
|||
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
|
||||
</span>
|
||||
<span *ngIf="prop._required" class="param-required">Required</span>
|
||||
<span *ngIf="prop['x-nullable']" class="param-nullable">Nullable</span>
|
||||
<div *ngIf="prop.default">Default: {{prop.default | json}}</div>
|
||||
<div *ngIf="prop.enum && !prop.isDiscriminator" class="param-enum">
|
||||
<span *ngFor="let enumItem of prop.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span>
|
||||
|
|
|
@ -47,12 +47,28 @@ export class JsonSchema extends BaseComponent implements OnInit {
|
|||
|
||||
this.pointer = activeDescendant.$ref;
|
||||
this.schema = this.specMgr.byPointer(this.pointer);
|
||||
this.schema = this.normalizer.normalize(this.schema, this.normPointer, {omitParent: false});
|
||||
this.schema = this.normalizer.normalize(this.schema, this.normPointer,
|
||||
{resolved: true});
|
||||
this.preprocessSchema();
|
||||
}
|
||||
|
||||
initDescendants() {
|
||||
this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer);
|
||||
if (!this.descendants.length) return;
|
||||
this.hasDescendants = true;
|
||||
let discriminator = this.schema.discriminator;
|
||||
let discrProperty = this.schema._properties &&
|
||||
this.schema._properties.filter((prop) => prop.name === discriminator)[0];
|
||||
if (discrProperty && discrProperty.enum) {
|
||||
let enumOrder = {};
|
||||
discrProperty.enum.forEach((enumItem, idx) => {
|
||||
enumOrder[enumItem.val] = idx;
|
||||
});
|
||||
|
||||
this.schema._descendants.sort((a, b) => {
|
||||
return enumOrder[a.name] > enumOrder[b.name] ? 1 : -1;
|
||||
});
|
||||
}
|
||||
this.selectDescendant(0);
|
||||
}
|
||||
|
||||
|
@ -65,7 +81,7 @@ export class JsonSchema extends BaseComponent implements OnInit {
|
|||
|
||||
this.applyStyling();
|
||||
|
||||
this.schema = this.normalizer.normalize(this.schema, this.normPointer);
|
||||
this.schema = this.normalizer.normalize(this.schema, this.normPointer, {resolved: true});
|
||||
this.schema = SchemaHelper.unwrapArray(this.schema, this.normPointer);
|
||||
this.initDescendants();
|
||||
this.preprocessSchema();
|
||||
|
|
|
@ -22,9 +22,8 @@
|
|||
--></span>
|
||||
</div>
|
||||
|
||||
<div *ngIf="method.bodyParam">
|
||||
<br>
|
||||
<request-samples [pointer]="pointer" [schemaPointer]="method.bodyParam._pointer">
|
||||
<div>
|
||||
<request-samples [pointer]="pointer" [schemaPointer]="method.bodyParam?._pointer">
|
||||
</request-samples>
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
padding-bottom: 100px;
|
||||
display: block;
|
||||
border-bottom: 1px solid rgba(127, 127, 127, 0.25);
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
:host:last-of-type {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<div class="body-param-description" [innerHtml]="bodyParam.description | marked"></div>
|
||||
<div>
|
||||
<br>
|
||||
<json-schema-lazy [isRequestSchema]="true" [auto]="true" pointer="{{bodyParam.pointer}}/schema">
|
||||
<json-schema-lazy [isRequestSchema]="true" [auto]="true" pointer="{{bodyParam._pointer}}/schema">
|
||||
</json-schema-lazy>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -40,7 +40,6 @@ export class ParamsList extends BaseComponent implements OnInit {
|
|||
|
||||
if (paramsMap.body && paramsMap.body.length) {
|
||||
let bodyParam = paramsMap.body[0];
|
||||
bodyParam.pointer = bodyParam._pointer;
|
||||
this.bodyParam = bodyParam;
|
||||
paramsMap.body = undefined;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<header *ngIf="schemaPointer || samples.length"> Request samples </header>
|
||||
<schema-sample *ngIf="!samples.length" [skipReadOnly]="true" [pointer]="schemaPointer"> </schema-sample>
|
||||
<schema-sample *ngIf="schemaPointer && !samples.length" [skipReadOnly]="true" [pointer]="schemaPointer"> </schema-sample>
|
||||
<tabs *ngIf="samples.length" [selected] = "selectedLang" (change)=changeLangNotify($event)>
|
||||
<tab tabTitle="JSON">
|
||||
<tab *ngIf="schemaPointer" tabTitle="JSON">
|
||||
<schema-sample [pointer]="schemaPointer" [skipReadOnly]="true"> </schema-sample>
|
||||
</tab>
|
||||
<tab *ngFor="let sample of samples" [tabTitle]="sample.lang">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import { Component, ViewChildren, QueryList, EventEmitter, Input,
|
||||
ChangeDetectionStrategy, OnInit } from '@angular/core';
|
||||
ChangeDetectionStrategy, OnInit, HostBinding } from '@angular/core';
|
||||
|
||||
import { BaseComponent, SpecManager } from '../base';
|
||||
import JsonPointer from '../../utils/JsonPointer';
|
||||
|
@ -18,6 +18,7 @@ export class RequestSamples extends BaseComponent implements OnInit {
|
|||
@Input() pointer:string;
|
||||
@Input() schemaPointer:string;
|
||||
@ViewChildren(Tabs) childQuery:QueryList<Tabs>;
|
||||
@HostBinding('attr.hidden') hidden;
|
||||
|
||||
childTabs: Tabs;
|
||||
selectedLang: EventEmitter<any>;
|
||||
|
@ -35,8 +36,9 @@ export class RequestSamples extends BaseComponent implements OnInit {
|
|||
}
|
||||
|
||||
init() {
|
||||
this.schemaPointer = JsonPointer.join(this.schemaPointer, 'schema');;
|
||||
this.schemaPointer = this.schemaPointer ? JsonPointer.join(this.schemaPointer, 'schema') : null;
|
||||
this.samples = this.componentSchema['x-code-samples'] || [];
|
||||
if (!this.schemaPointer && !this.samples.length) this.hidden = true;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
|
|
@ -163,7 +163,7 @@ const injectors = {
|
|||
range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ]`;
|
||||
} else if (propertySchema.maxLength) {
|
||||
range = '<= ' + propertySchema.maxLength;
|
||||
} else if (propertySchema.minimum) {
|
||||
} else if (propertySchema.minLength) {
|
||||
range = '>= ' + propertySchema.minLength;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,17 +24,20 @@ export class SchemaNormalizer {
|
|||
this._dereferencer = new SchemaDereferencer(_schema, this);
|
||||
}
|
||||
normalize(schema, ptr, opts:any ={}) {
|
||||
opts.omitParent = opts.omitParent !== false;
|
||||
let hasPtr = !!schema.$ref;
|
||||
if (opts.resolved && !hasPtr) this._dereferencer.visit(ptr);
|
||||
|
||||
if (schema['x-redoc-normalized']) return schema;
|
||||
let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => {
|
||||
let resolved = this._dereferencer.dereference(subSchema, ptr);
|
||||
if (resolved.allOf) {
|
||||
resolved._pointer = resolved._pointer || ptr;
|
||||
resolved = Object.assign({}, resolved);
|
||||
AllOfMerger.merge(resolved, resolved.allOf, {omitParent: opts.omitParent});
|
||||
AllOfMerger.merge(resolved, resolved.allOf);
|
||||
}
|
||||
return resolved;
|
||||
});
|
||||
if (opts.resolved && !hasPtr) this._dereferencer.exit(ptr);
|
||||
res['x-redoc-normalized'] = true;
|
||||
return res;
|
||||
}
|
||||
|
@ -88,12 +91,11 @@ class SchemaWalker {
|
|||
}
|
||||
|
||||
class AllOfMerger {
|
||||
static merge(into, schemas, opts) {
|
||||
static merge(into, schemas) {
|
||||
into['x-derived-from'] = [];
|
||||
for (let i=0; i < schemas.length; i++) {
|
||||
let subSchema = schemas[i];
|
||||
into['x-derived-from'].push(subSchema._pointer);
|
||||
if (opts && opts.omitParent && subSchema.discriminator) continue;
|
||||
|
||||
AllOfMerger.checkCanMerge(subSchema, into);
|
||||
|
||||
|
@ -177,6 +179,14 @@ class SchemaDereferencer {
|
|||
constructor(private _spec: SpecManager, private normalizator: SchemaNormalizer) {
|
||||
}
|
||||
|
||||
visit($ref) {
|
||||
this._refCouner.visit($ref);
|
||||
}
|
||||
|
||||
exit($ref) {
|
||||
this._refCouner.exit($ref);
|
||||
}
|
||||
|
||||
dereference(schema: Reference, pointer:string):any {
|
||||
if (!schema || !schema.$ref) return schema;
|
||||
window['derefCount'] = window['derefCount'] ? window['derefCount'] + 1 : 1;
|
||||
|
|
|
@ -27,10 +27,23 @@ describe('Common components', () => {
|
|||
expect(component).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should start sticked', () => {
|
||||
it('should start unsticked', () => {
|
||||
spyOn(component, 'stick').and.callThrough();
|
||||
spyOn(component, 'stickBottom').and.callThrough();
|
||||
fixture.detectChanges();
|
||||
expect(component.stick).toHaveBeenCalled();
|
||||
expect(component.stick).not.toHaveBeenCalled();
|
||||
expect(component.stickBottom).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should stick to the top on the next VM tick', (done) => {
|
||||
spyOn(component, 'stick').and.callThrough();
|
||||
spyOn(component, 'stickBottom').and.callThrough();
|
||||
fixture.detectChanges();
|
||||
setTimeout(() => {
|
||||
expect(component.stick).toHaveBeenCalled();
|
||||
expect(component.stickBottom).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should stick if scrolled more than scrollYOffset', () => {
|
||||
|
@ -42,6 +55,8 @@ describe('Common components', () => {
|
|||
component.updatePosition();
|
||||
expect(component.stick).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// TODO: add tests for stickBottom
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -32,11 +32,24 @@ export class StickySidebar implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
updatePosition() {
|
||||
var stuck = false;
|
||||
if ( this.scrollY + this.scrollYOffset() >= this.$redocEl.offsetTop) {
|
||||
this.stick();
|
||||
stuck = true;
|
||||
} else {
|
||||
this.unstick();
|
||||
}
|
||||
|
||||
if ( this.scrollY + window.innerHeight - this.scrollYOffset() >= this.$redocEl.scrollHeight) {
|
||||
this.stickBottom();
|
||||
stuck = true;
|
||||
} else {
|
||||
this.unstickBottom();
|
||||
}
|
||||
|
||||
if (!stuck) {
|
||||
DOM.setStyle(this.$element, 'position', 'absolute');
|
||||
}
|
||||
}
|
||||
|
||||
stick() {
|
||||
|
@ -45,19 +58,33 @@ export class StickySidebar implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
unstick() {
|
||||
DOM.setStyle(this.$element, 'position', 'absolute');
|
||||
DOM.setStyle(this.$element, 'top', '0');
|
||||
}
|
||||
|
||||
stickBottom() {
|
||||
DOM.setStyle(this.$element, 'position', 'fixed');
|
||||
var offset = this.scrollY + this.scrollParentHeight - (this.$redocEl.scrollHeight + this.$redocEl.offsetTop);
|
||||
DOM.setStyle(this.$element, 'bottom', offset + 'px');
|
||||
}
|
||||
|
||||
unstickBottom() {
|
||||
DOM.setStyle(this.$element, 'bottom', '0');
|
||||
}
|
||||
|
||||
get scrollY() {
|
||||
return (this.scrollParent.pageYOffset != undefined) ? this.scrollParent.pageYOffset : this.scrollParent.scrollTop;
|
||||
}
|
||||
|
||||
get scrollParentHeight() {
|
||||
return (this.scrollParent.innerHeight != undefined) ? this.scrollParent.innerHeight : this.scrollParent.clientHeight;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// FIXME use more reliable code
|
||||
this.$redocEl = this.$element.offsetParent.parentNode || DOM.defaultDoc().body;
|
||||
this.bind();
|
||||
this.updatePosition();
|
||||
setTimeout(() => this.updatePosition());
|
||||
//this.updatePosition()
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
|
|
@ -41,7 +41,7 @@ export class ValuesPipe implements PipeTransform {
|
|||
|
||||
@Pipe({ name: 'jsonPointerEscape' })
|
||||
export class JsonPointerEscapePipe implements PipeTransform {
|
||||
transform(value) {
|
||||
transform(value:string) {
|
||||
if (isBlank(value)) return value;
|
||||
if (!isString(value)) {
|
||||
throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value);
|
||||
|
@ -53,7 +53,7 @@ export class JsonPointerEscapePipe implements PipeTransform {
|
|||
@Pipe({ name: 'marked' })
|
||||
export class MarkedPipe implements PipeTransform {
|
||||
constructor(private sanitizer: DomSanitizationService) {}
|
||||
transform(value) {
|
||||
transform(value:string) {
|
||||
if (isBlank(value)) return value;
|
||||
if (!isString(value)) {
|
||||
throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value);
|
||||
|
@ -68,7 +68,7 @@ export class MarkedPipe implements PipeTransform {
|
|||
@Pipe({ name: 'safe' })
|
||||
export class SafePipe implements PipeTransform {
|
||||
constructor(private sanitizer: DomSanitizationService) {}
|
||||
transform(value) {
|
||||
transform(value:string) {
|
||||
if (isBlank(value)) return value;
|
||||
if (!isString(value)) {
|
||||
throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value);
|
||||
|
@ -109,7 +109,7 @@ export class PrismPipe implements PipeTransform {
|
|||
|
||||
@Pipe({ name: 'encodeURIComponent' })
|
||||
export class EncodeURIComponentPipe implements PipeTransform {
|
||||
transform(value) {
|
||||
transform(value:string) {
|
||||
if (isBlank(value)) return value;
|
||||
if (!isString(value)) {
|
||||
throw new InvalidPipeArgumentException(EncodeURIComponentPipe, value);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "redoc",
|
||||
"description": "Swagger-generated API Reference Documentation",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/Rebilly/ReDoc"
|
||||
|
@ -24,7 +24,8 @@
|
|||
"e2e-server": "http-server -p 3000 tests/e2e",
|
||||
"e2e-copy": "cp dist/redoc.min.js tests/e2e/",
|
||||
"webdriver": "webdriver-manager update",
|
||||
"serve:prod": "NODE_ENV=production npm start"
|
||||
"serve:prod": "NODE_ENV=production npm start",
|
||||
"protractor": "protractor"
|
||||
},
|
||||
"keywords": [
|
||||
"OpenAPI",
|
||||
|
|
|
@ -51,7 +51,8 @@ function verifyNoBrowserErrors() {
|
|||
if (message.match(/^Unknown property.*Declaration dropped/)) return false;
|
||||
if (message.match(/^Error in parsing value for.*Declaration dropped/)) return false;
|
||||
if (message.indexOf('The character encoding of the HTML document was not declared') > -1) return false;
|
||||
if (message.match(/addons.manager\s+DEBUG/)) return false;
|
||||
if (message.match(/^\d{13}\s+(DeferredSave|addons)/)) return false;
|
||||
if (message.match(/This site makes use of a SHA-1 Certificate/)) return false;
|
||||
|
||||
|
||||
if (logEntry.level.value >= LogLevel.INFO) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
window.redocError = null;
|
||||
/* init redoc */
|
||||
var url = window.location.search.substr(5) || 'http://rebilly.github.io/SwaggerTemplateRepo/swagger.json';
|
||||
Redoc.init(decodeURIComponent(url), {disableLazySchemas: true}).then(function() {}, function(err) {
|
||||
Redoc.init(decodeURIComponent(url), {disableLazySchemas: true, suppressWarnings: true}).then(function() {}, function(err) {
|
||||
window.redocError = err;
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue
Block a user