public SchemaGenerator(SchemaGeneratorOptions schemaGeneratorOptions, JsonSerializerSettings jsonSerializerSettings) { _jsonContractResolver = jsonSerializerSettings.ContractResolver ?? new DefaultContractResolver(); // To manage complexity, implement as a chain of responsibility _chainOfHandlers = new KnownTypeHandler(schemaGeneratorOptions, this, jsonSerializerSettings) .Add(new ReferenceableTypeHandler(schemaGeneratorOptions, this, jsonSerializerSettings)) .Add(new PolymorphicTypeHandler(schemaGeneratorOptions, this, jsonSerializerSettings)) .Add(new JsonPrimitiveHandler(schemaGeneratorOptions, this, jsonSerializerSettings)) .Add(new JsonArrayHandler(schemaGeneratorOptions, this, jsonSerializerSettings)) .Add(new JsonDictionaryHandler(schemaGeneratorOptions, this, jsonSerializerSettings)) .Add(new JsonObjectHandler(schemaGeneratorOptions, this, jsonSerializerSettings)) .Add(new FallbackHandler(schemaGeneratorOptions, this, jsonSerializerSettings)); }
protected override OpenApiSchema GenerateSchemaFor(ModelMetadata modelMetadata, SchemaRepository schemaRepository, JsonContract jsonContract) { if (!schemaRepository.TryGetIdFor(modelMetadata.ModelType, out string schemaId)) { schemaId = SchemaGeneratorOptions.SchemaIdSelector(modelMetadata.ModelType); schemaRepository.ReserveIdFor(modelMetadata.ModelType, schemaId); schemaRepository.AddSchemaFor(modelMetadata.ModelType, Next.GenerateSchema(modelMetadata, schemaRepository, jsonContract)); } return(new OpenApiSchema { Reference = new OpenApiReference { Id = schemaId, Type = ReferenceType.Schema } }); }
protected override OpenApiSchema GenerateSchemaFor(ModelMetadata modelMetadata, SchemaRepository schemaRepository, JsonContract jsonContract) { var schema = new OpenApiSchema { OneOf = new List <OpenApiSchema>() }; foreach (var subType in SchemaGeneratorOptions.SubTypesResolver(modelMetadata.ModelType)) { var subTypeMetadata = modelMetadata.GetMetadataForType(subType); var subSchema = SchemaGenerator.GenerateSchema(subTypeMetadata, schemaRepository); schema.OneOf.Add(subSchema); } return(schema); }
public SchemaGenerator(JsonSerializerSettings jsonSerializerSettings, SchemaGeneratorOptions options) { // NOTE: An OpenApiSchema MAY be used to describe both JSON and non-JSON media types. However, this implementation of ISchemaGenerator is optimized // for JSON and therefore couples to several JSON.NET abstractions so that it can provide accurate descriptions of types in their serialized form. _jsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings(); _jsonContractResolver = _jsonSerializerSettings.ContractResolver ?? new DefaultContractResolver(); _options = options ?? new SchemaGeneratorOptions(); _subGenerators = new ISchemaGenerator[] { new PolymorphicSchemaGenerator(_options, this), new JsonPrimitiveSchemaGenerator(_options, _jsonContractResolver, _jsonSerializerSettings), new JsonDictionarySchemaGenerator(_options, _jsonContractResolver, this), new JsonArraySchemaGenerator(_options, _jsonContractResolver, this), new JsonObjectSchemaGenerator(_options, _jsonContractResolver, this), }; }
public SchemaGenerator(SchemaGeneratorOptions options, JsonSerializerSettings serializerSettings) { options = options ?? new SchemaGeneratorOptions(); // NOTE: An OpenApiSchema MAY be used to describe both JSON and non-JSON media types. However, this implementation of ISchemaGenerator // is optimized for JSON and therefore couples to several JSON.NET abstractions so that it can provide accurate descriptions of types // in their serialized form. serializerSettings = serializerSettings ?? new JsonSerializerSettings(); var contractResolver = serializerSettings.ContractResolver ?? new DefaultContractResolver(); _generatorChain = new TypeSpecificSchemaGenerator(options, this, contractResolver) .Add(new FileSchemaGenerator(options, this, contractResolver)) .Add(new ReferencedSchemaGenerator(options, this, contractResolver)) .Add(new PolymorphicSchemaGenerator(options, this, contractResolver)) .Add(new PrimitiveSchemaGenerator(options, this, contractResolver, serializerSettings)) .Add(new DictionarySchemaGenerator(options, this, contractResolver)) .Add(new ArraySchemaGenerator(options, this, contractResolver)) .Add(new ObjectSchemaGenerator(options, this, contractResolver)); }
public FallbackHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator) : base(options, schemaGenerator) { }
protected override bool CanGenerateSchemaFor(ModelMetadata modelMetadata, JsonContract jsonContract) { return(SchemaGeneratorOptions.GeneratePolymorphicSchemas && SchemaGeneratorOptions.SubTypesResolver(modelMetadata.ModelType).Any()); }
protected SchemaGeneratorBase(SchemaGeneratorOptions generatorOptions) { _generatorOptions = generatorOptions; _handlers = new List <SchemaGeneratorHandler>(); }
public FormFileSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver) : base(options, rootGenerator, contractResolver) { }
public JsonObjectHandler(SchemaGeneratorOptions generatorOptions, JsonSerializerOptions serializerOptions, ISchemaGenerator schemaGenerator) { _generatorOptions = generatorOptions; _serializerOptions = serializerOptions; _schemaGenerator = schemaGenerator; }
public JsonArrayHandler(SchemaGeneratorOptions schemaGeneratorOptions, SchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings) : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings) { }
public KnownTypeHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings) : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings) { }
public SchemaGenerator(SchemaGeneratorOptions generatorOptions, ISerializerDataContractResolver serializerDataContractResolver) { _generatorOptions = generatorOptions; _serializerDataContractResolver = serializerDataContractResolver; }
protected ChainableSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver) { Options = options; RootGenerator = rootGenerator; ContractResolver = contractResolver; }
public ReferenceableTypeHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings) : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings) { }
protected ApiModelHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator) { Options = options; Generator = schemaGenerator; }
public FileTypeHandler(SchemaGeneratorOptions options, ISchemaGenerator generator) : base(options, generator) { }
public JsonEnumHandler(SchemaGeneratorOptions generatorOptions, JsonSerializerOptions serializerOptions) { _generatorOptions = generatorOptions; _serializerOptions = serializerOptions; }
public PolymorphicTypeHandler(SchemaGeneratorOptions generatorOptions, ISchemaGenerator schemaGenerator) { _generatorOptions = generatorOptions; _schemaGenerator = schemaGenerator; }
internal FallbackHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings) : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings) { }
public ApiDictionaryHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator) : base(options, schemaGenerator) { }
public SchemaGenerator(SchemaGeneratorOptions generatorOptions, ISerializerBehavior serializerBehavior) { _generatorOptions = generatorOptions; _serializerBehavior = serializerBehavior; }
public PolymorphicSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator) { _options = options; _schemaGenerator = schemaGenerator; }
public PolymorphicTypeHandler(SchemaGeneratorOptions options, SchemaGenerator generator) : base(options, generator) { }
public ApiObjectHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator) : base(schemaGeneratorOptions, schemaGenerator) { }
public DictionarySchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver) : base(options, rootGenerator, contractResolver) { }
public SchemaGenerator(SchemaGeneratorOptions generatorOptions, IDataContractResolver dataContractResolver) { _generatorOptions = generatorOptions; _dataContractResolver = dataContractResolver; }
public ReferencedSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver) : base(options, rootGenerator, contractResolver) { }
public SchemaGenerator(SchemaGeneratorOptions generatorOptions, ISerializerMetadataResolver serializerMetadataResolver) { _generatorOptions = generatorOptions; _serializerMetadataResolver = serializerMetadataResolver; }
public ApiPrimitiveHandler(SchemaGeneratorOptions options, ISchemaGenerator generator) : base(options, generator) { }