mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-11-04 09:47:31 +03:00 
			
		
		
		
	Add type:file support for payloads
This commit is contained in:
		
							parent
							
								
									3f725056ed
								
							
						
					
					
						commit
						547cf0ceab
					
				| 
						 | 
					@ -14,7 +14,7 @@ var cache = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'json-schema-lazy',
 | 
					  selector: 'json-schema-lazy',
 | 
				
			||||||
  inputs: ['pointer', 'auto', 'skipReadOnly'],
 | 
					  inputs: ['pointer', 'auto', 'isRequestSchema'],
 | 
				
			||||||
  template: '',
 | 
					  template: '',
 | 
				
			||||||
  directives: [CORE_DIRECTIVES]
 | 
					  directives: [CORE_DIRECTIVES]
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
| 
						 | 
					@ -91,7 +91,7 @@ export class JsonSchemaLazy {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  initComponent(compRef) {
 | 
					  initComponent(compRef) {
 | 
				
			||||||
    compRef.instance.pointer = this.pointer;
 | 
					    compRef.instance.pointer = this.pointer;
 | 
				
			||||||
    compRef.instance.skipReadOnly = this.skipReadOnly;
 | 
					    compRef.instance.isRequestSchema = this.isRequestSchema;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngAfterViewInit() {
 | 
					  ngAfterViewInit() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,13 @@
 | 
				
			||||||
<span *ngIf="schema.isTrivial" class="param-wrap">
 | 
					<span *ngIf="schema.isFile" class="param-wrap">
 | 
				
			||||||
 | 
					  <span class="param-file">file</span>
 | 
				
			||||||
 | 
					  <div *ngIf="schema._produces && !isRequestSchema" class="file produces">
 | 
				
			||||||
 | 
					    Produces: {{ schema._produces | json }}
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					  <div *ngIf="schema._consumes && isRequestSchema" class="file consume">
 | 
				
			||||||
 | 
					    Consumes: {{ schema._consumes | json }}
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					</span>
 | 
				
			||||||
 | 
					<span *ngIf="schema.isTrivial && !schema.isFile" class="param-wrap">
 | 
				
			||||||
  <span class="param-type param-type-trivial {{schema.type}}"
 | 
					  <span class="param-type param-type-trivial {{schema.type}}"
 | 
				
			||||||
    [ngClass]="{'with-hint': schema._displayTypeHint}"
 | 
					    [ngClass]="{'with-hint': schema._displayTypeHint}"
 | 
				
			||||||
    title="{{schema._displayTypeHint}}">{{schema._displayType}} {{schema._displayFormat}}
 | 
					    title="{{schema._displayTypeHint}}">{{schema._displayType}} {{schema._displayFormat}}
 | 
				
			||||||
| 
						 | 
					@ -43,7 +52,7 @@
 | 
				
			||||||
    <tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" *ngIf="prop._pointer">
 | 
					    <tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" *ngIf="prop._pointer">
 | 
				
			||||||
      <td colspan="2">
 | 
					      <td colspan="2">
 | 
				
			||||||
        <json-schema class="nested-schema" pointer="{{prop._pointer}}" [isArray]='prop._isArray'
 | 
					        <json-schema class="nested-schema" pointer="{{prop._pointer}}" [isArray]='prop._isArray'
 | 
				
			||||||
        [nestOdd]="!nestOdd" [skipReadOnly]="skipReadOnly" [attr.nesteven]="!nestOdd">
 | 
					        [nestOdd]="!nestOdd" [isRequestSchema]="isRequestSchema" [attr.nesteven]="!nestOdd">
 | 
				
			||||||
        </json-schema>
 | 
					        </json-schema>
 | 
				
			||||||
      </td>
 | 
					      </td>
 | 
				
			||||||
    </tr>
 | 
					    </tr>
 | 
				
			||||||
| 
						 | 
					@ -52,7 +61,7 @@
 | 
				
			||||||
    <td colspan="2">
 | 
					    <td colspan="2">
 | 
				
			||||||
      <div class="derived-schema" *ngFor="let derived of schema.derived" [ngClass]="{active: derived.active}">
 | 
					      <div class="derived-schema" *ngFor="let derived of schema.derived" [ngClass]="{active: derived.active}">
 | 
				
			||||||
        <json-schema class="discriminator-part" *ngIf="!derived.empty" [childFor]="pointer"
 | 
					        <json-schema class="discriminator-part" *ngIf="!derived.empty" [childFor]="pointer"
 | 
				
			||||||
        pointer="{{derived.$ref}}" [final]="derived.final" [skipReadOnly]="skipReadOnly">
 | 
					        pointer="{{derived.$ref}}" [final]="derived.final" [isRequestSchema]="isRequestSchema">
 | 
				
			||||||
        </json-schema>
 | 
					        </json-schema>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    </td>
 | 
					    </td>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ import JsonPointer from '../../utils/JsonPointer';
 | 
				
			||||||
  templateUrl: './lib/components/JsonSchema/json-schema.html',
 | 
					  templateUrl: './lib/components/JsonSchema/json-schema.html',
 | 
				
			||||||
  styleUrls: ['./lib/components/JsonSchema/json-schema.css'],
 | 
					  styleUrls: ['./lib/components/JsonSchema/json-schema.css'],
 | 
				
			||||||
  directives: [JsonSchema, DropDown],
 | 
					  directives: [JsonSchema, DropDown],
 | 
				
			||||||
  inputs: ['isArray', 'final', 'nestOdd', 'childFor', 'skipReadOnly']
 | 
					  inputs: ['isArray', 'final', 'nestOdd', 'childFor', 'isRequestSchema']
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
 | 
					@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
 | 
				
			||||||
export class JsonSchema extends BaseComponent {
 | 
					export class JsonSchema extends BaseComponent {
 | 
				
			||||||
| 
						 | 
					@ -53,8 +53,8 @@ export class JsonSchema extends BaseComponent {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let schema = this.componentSchema;
 | 
					    let schema = this.componentSchema;
 | 
				
			||||||
    BaseComponent.joinAllOf(schema, {omitParent: true});
 | 
					    BaseComponent.joinAllOf(schema, {omitParent: true});
 | 
				
			||||||
    schema = this.unwrapArray(schema);
 | 
					    this.schema = schema = this.unwrapArray(schema);
 | 
				
			||||||
    runInjectors(schema, schema, schema._pointer || this.pointer);
 | 
					    runInjectors(schema, schema, schema._pointer || this.pointer, this.pointer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    schema.derived = schema.derived || [];
 | 
					    schema.derived = schema.derived || [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,7 +62,6 @@ export class JsonSchema extends BaseComponent {
 | 
				
			||||||
      this.prepareObjectPropertiesData(schema);
 | 
					      this.prepareObjectPropertiesData(schema);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.schema = schema;
 | 
					 | 
				
			||||||
    this.initDerived();
 | 
					    this.initDerived();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,7 +118,8 @@ export class JsonSchema extends BaseComponent {
 | 
				
			||||||
      let discrProp = props.splice(discriminatorFieldIdx, 1);
 | 
					      let discrProp = props.splice(discriminatorFieldIdx, 1);
 | 
				
			||||||
      props.push(discrProp[0]);
 | 
					      props.push(discrProp[0]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (this.skipReadOnly) {
 | 
					    // filter readOnly props for request schemas
 | 
				
			||||||
 | 
					    if (this.isRequestSchema) {
 | 
				
			||||||
      props = props.filter(prop => !prop.readOnly);
 | 
					      props = props.filter(prop => !prop.readOnly);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    schema.properties = props;
 | 
					    schema.properties = props;
 | 
				
			||||||
| 
						 | 
					@ -131,21 +131,21 @@ export class JsonSchema extends BaseComponent {
 | 
				
			||||||
      JsonPointer.join(addProps._pointer || schema._pointer || this.pointer, ['additionalProperties']));
 | 
					      JsonPointer.join(addProps._pointer || schema._pointer || this.pointer, ['additionalProperties']));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static injectPropertyData(propertySchema, propertyName, propPointer) {
 | 
					  static injectPropertyData(propertySchema, propertyName, propPointer, hostPointer) {
 | 
				
			||||||
    propertySchema = Object.assign({}, propertySchema);
 | 
					    propertySchema = Object.assign({}, propertySchema);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    propertySchema._name = propertyName;
 | 
					    propertySchema._name = propertyName;
 | 
				
			||||||
    runInjectors(propertySchema, propertySchema, propPointer);
 | 
					    runInjectors(propertySchema, propertySchema, propPointer, hostPointer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return propertySchema;
 | 
					    return propertySchema;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function runInjectors(injectTo, propertySchema, propertyPointer) {
 | 
					function runInjectors(injectTo, propertySchema, propertyPointer, hostPointer) {
 | 
				
			||||||
  for (var injName in injectors) {
 | 
					  for (var injName in injectors) {
 | 
				
			||||||
    let injector = injectors[injName];
 | 
					    let injector = injectors[injName];
 | 
				
			||||||
    if (injector.check(propertySchema)) {
 | 
					    if (injector.check(propertySchema)) {
 | 
				
			||||||
      injector.inject(injectTo, propertySchema, propertyPointer);
 | 
					      injector.inject(injectTo, propertySchema, propertyPointer, hostPointer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -183,7 +183,6 @@ const injectors = {
 | 
				
			||||||
      runInjectors(injectTo, propertySchema.items, propPointer);
 | 
					      runInjectors(injectTo, propertySchema.items, propPointer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					 | 
				
			||||||
  object: {
 | 
					  object: {
 | 
				
			||||||
    check: (propertySchema) => {
 | 
					    check: (propertySchema) => {
 | 
				
			||||||
      return propertySchema.type === 'object' && propertySchema.properties;
 | 
					      return propertySchema.type === 'object' && propertySchema.properties;
 | 
				
			||||||
| 
						 | 
					@ -201,7 +200,6 @@ const injectors = {
 | 
				
			||||||
      injectTo.isTrivial = true;
 | 
					      injectTo.isTrivial = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					 | 
				
			||||||
  simpleType: {
 | 
					  simpleType: {
 | 
				
			||||||
    check: (propertySchema) => {
 | 
					    check: (propertySchema) => {
 | 
				
			||||||
      if (propertySchema.type === 'object') {
 | 
					      if (propertySchema.type === 'object') {
 | 
				
			||||||
| 
						 | 
					@ -258,5 +256,23 @@ const injectors = {
 | 
				
			||||||
        injectTo._range = range + ' characters';
 | 
					        injectTo._range = range + ' characters';
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  file: {
 | 
				
			||||||
 | 
					    check: propertySchema => (propertySchema.type === 'file'),
 | 
				
			||||||
 | 
					    inject: (injectTo, propertySchema = injectTo, propPointer, hostPointer) => {
 | 
				
			||||||
 | 
					      injectTo.isFile = true;
 | 
				
			||||||
 | 
					      let parentPtr;
 | 
				
			||||||
 | 
					      if (propertySchema.in === 'formData') {
 | 
				
			||||||
 | 
					        parentPtr = JsonPointer.dirName(hostPointer, 1);
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        parentPtr = JsonPointer.dirName(hostPointer, 3);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      let parentParam = SchemaManager.instance().byPointer(parentPtr);
 | 
				
			||||||
 | 
					      let root = SchemaManager.instance().schema;
 | 
				
			||||||
 | 
					      injectTo._produces = parentParam && parentParam.produces || root.produces;
 | 
				
			||||||
 | 
					      injectTo._consumes = parentParam && parentParam.consumes || root.consumes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@
 | 
				
			||||||
  <div class="body-param-description" innerHtml="{{data.bodyParam.description | marked}}"></div>
 | 
					  <div class="body-param-description" innerHtml="{{data.bodyParam.description | marked}}"></div>
 | 
				
			||||||
  <div>
 | 
					  <div>
 | 
				
			||||||
    <br>
 | 
					    <br>
 | 
				
			||||||
    <json-schema-lazy [skipReadOnly]="true" [auto]="true" pointer="{{data.bodyParam.pointer}}/schema">
 | 
					    <json-schema-lazy [isRequestSchema]="true" [auto]="true" pointer="{{data.bodyParam.pointer}}/schema">
 | 
				
			||||||
    </json-schema-lazy>
 | 
					    </json-schema-lazy>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ export class ParamsList extends BaseComponent {
 | 
				
			||||||
    paramsList = paramsList.map((paramData) => {
 | 
					    paramsList = paramsList.map((paramData) => {
 | 
				
			||||||
      let propPointer = paramData._pointer;
 | 
					      let propPointer = paramData._pointer;
 | 
				
			||||||
      if (paramData.in === 'body') return paramData;
 | 
					      if (paramData.in === 'body') return paramData;
 | 
				
			||||||
      return JsonSchema.injectPropertyData(paramData, paramData.name, propPointer);
 | 
					      return JsonSchema.injectPropertyData(paramData, paramData.name, propPointer, this.pointer);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let paramsMap = this.orderParams(paramsList);
 | 
					    let paramsMap = this.orderParams(paramsList);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  "name": "redoc",
 | 
					  "name": "redoc",
 | 
				
			||||||
  "description": "Swagger-generated API Reference Documentation",
 | 
					  "description": "Swagger-generated API Reference Documentation",
 | 
				
			||||||
  "version": "0.9.0",
 | 
					  "version": "0.10.0",
 | 
				
			||||||
  "repository": {
 | 
					  "repository": {
 | 
				
			||||||
    "type": "git",
 | 
					    "type": "git",
 | 
				
			||||||
    "url": "git://github.com/Rebilly/ReDoc"
 | 
					    "url": "git://github.com/Rebilly/ReDoc"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user