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));
        }
Beispiel #2
0
        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));
        }
Beispiel #6
0
 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());
 }
Beispiel #8
0
 protected SchemaGeneratorBase(SchemaGeneratorOptions generatorOptions)
 {
     _generatorOptions = generatorOptions;
     _handlers         = new List <SchemaGeneratorHandler>();
 }
 public FormFileSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver)
     : base(options, rootGenerator, contractResolver)
 {
 }
Beispiel #10
0
 public JsonObjectHandler(SchemaGeneratorOptions generatorOptions, JsonSerializerOptions serializerOptions, ISchemaGenerator schemaGenerator)
 {
     _generatorOptions  = generatorOptions;
     _serializerOptions = serializerOptions;
     _schemaGenerator   = schemaGenerator;
 }
Beispiel #11
0
 public JsonArrayHandler(SchemaGeneratorOptions schemaGeneratorOptions, SchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings)
     : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings)
 {
 }
Beispiel #12
0
 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;
 }
Beispiel #15
0
 public ReferenceableTypeHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings)
     : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings)
 {
 }
Beispiel #16
0
 protected ApiModelHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator)
 {
     Options   = options;
     Generator = schemaGenerator;
 }
 public FileTypeHandler(SchemaGeneratorOptions options, ISchemaGenerator generator)
     : base(options, generator)
 {
 }
Beispiel #18
0
 public JsonEnumHandler(SchemaGeneratorOptions generatorOptions, JsonSerializerOptions serializerOptions)
 {
     _generatorOptions  = generatorOptions;
     _serializerOptions = serializerOptions;
 }
Beispiel #19
0
 public PolymorphicTypeHandler(SchemaGeneratorOptions generatorOptions, ISchemaGenerator schemaGenerator)
 {
     _generatorOptions = generatorOptions;
     _schemaGenerator  = schemaGenerator;
 }
Beispiel #20
0
 internal FallbackHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings)
     : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings)
 {
 }
Beispiel #21
0
 public ApiDictionaryHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator)
     : base(options, schemaGenerator)
 {
 }
Beispiel #22
0
 public SchemaGenerator(SchemaGeneratorOptions generatorOptions, ISerializerBehavior serializerBehavior)
 {
     _generatorOptions   = generatorOptions;
     _serializerBehavior = serializerBehavior;
 }
Beispiel #23
0
 public PolymorphicSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator)
 {
     _options         = options;
     _schemaGenerator = schemaGenerator;
 }
Beispiel #24
0
 public PolymorphicTypeHandler(SchemaGeneratorOptions options, SchemaGenerator generator)
     : base(options, generator)
 {
 }
 public ApiObjectHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator)
     : base(schemaGeneratorOptions, schemaGenerator)
 {
 }
Beispiel #26
0
 public DictionarySchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver)
     : base(options, rootGenerator, contractResolver)
 {
 }
Beispiel #27
0
 public SchemaGenerator(SchemaGeneratorOptions generatorOptions, IDataContractResolver dataContractResolver)
 {
     _generatorOptions     = generatorOptions;
     _dataContractResolver = dataContractResolver;
 }
Beispiel #28
0
 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)
 {
 }