コード例 #1
0
        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));
        }
コード例 #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
                }
            });
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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),
            };
        }
コード例 #5
0
        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));
        }
コード例 #6
0
 public FallbackHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator)
     : base(options, schemaGenerator)
 {
 }
コード例 #7
0
 protected override bool CanGenerateSchemaFor(ModelMetadata modelMetadata, JsonContract jsonContract)
 {
     return(SchemaGeneratorOptions.GeneratePolymorphicSchemas &&
            SchemaGeneratorOptions.SubTypesResolver(modelMetadata.ModelType).Any());
 }
コード例 #8
0
 protected SchemaGeneratorBase(SchemaGeneratorOptions generatorOptions)
 {
     _generatorOptions = generatorOptions;
     _handlers         = new List <SchemaGeneratorHandler>();
 }
コード例 #9
0
 public FormFileSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver)
     : base(options, rootGenerator, contractResolver)
 {
 }
コード例 #10
0
 public JsonObjectHandler(SchemaGeneratorOptions generatorOptions, JsonSerializerOptions serializerOptions, ISchemaGenerator schemaGenerator)
 {
     _generatorOptions  = generatorOptions;
     _serializerOptions = serializerOptions;
     _schemaGenerator   = schemaGenerator;
 }
コード例 #11
0
 public JsonArrayHandler(SchemaGeneratorOptions schemaGeneratorOptions, SchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings)
     : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings)
 {
 }
コード例 #12
0
 public KnownTypeHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings)
     : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings)
 {
 }
コード例 #13
0
 public SchemaGenerator(SchemaGeneratorOptions generatorOptions, ISerializerDataContractResolver serializerDataContractResolver)
 {
     _generatorOptions = generatorOptions;
     _serializerDataContractResolver = serializerDataContractResolver;
 }
コード例 #14
0
 protected ChainableSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver)
 {
     Options          = options;
     RootGenerator    = rootGenerator;
     ContractResolver = contractResolver;
 }
コード例 #15
0
 public ReferenceableTypeHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings)
     : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings)
 {
 }
コード例 #16
0
 protected ApiModelHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator)
 {
     Options   = options;
     Generator = schemaGenerator;
 }
コード例 #17
0
 public FileTypeHandler(SchemaGeneratorOptions options, ISchemaGenerator generator)
     : base(options, generator)
 {
 }
コード例 #18
0
 public JsonEnumHandler(SchemaGeneratorOptions generatorOptions, JsonSerializerOptions serializerOptions)
 {
     _generatorOptions  = generatorOptions;
     _serializerOptions = serializerOptions;
 }
コード例 #19
0
 public PolymorphicTypeHandler(SchemaGeneratorOptions generatorOptions, ISchemaGenerator schemaGenerator)
 {
     _generatorOptions = generatorOptions;
     _schemaGenerator  = schemaGenerator;
 }
コード例 #20
0
 internal FallbackHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator, JsonSerializerSettings jsonSerializerSettings)
     : base(schemaGeneratorOptions, schemaGenerator, jsonSerializerSettings)
 {
 }
コード例 #21
0
 public ApiDictionaryHandler(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator)
     : base(options, schemaGenerator)
 {
 }
コード例 #22
0
 public SchemaGenerator(SchemaGeneratorOptions generatorOptions, ISerializerBehavior serializerBehavior)
 {
     _generatorOptions   = generatorOptions;
     _serializerBehavior = serializerBehavior;
 }
コード例 #23
0
 public PolymorphicSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator schemaGenerator)
 {
     _options         = options;
     _schemaGenerator = schemaGenerator;
 }
コード例 #24
0
 public PolymorphicTypeHandler(SchemaGeneratorOptions options, SchemaGenerator generator)
     : base(options, generator)
 {
 }
コード例 #25
0
 public ApiObjectHandler(SchemaGeneratorOptions schemaGeneratorOptions, ISchemaGenerator schemaGenerator)
     : base(schemaGeneratorOptions, schemaGenerator)
 {
 }
コード例 #26
0
 public DictionarySchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver)
     : base(options, rootGenerator, contractResolver)
 {
 }
コード例 #27
0
 public SchemaGenerator(SchemaGeneratorOptions generatorOptions, IDataContractResolver dataContractResolver)
 {
     _generatorOptions     = generatorOptions;
     _dataContractResolver = dataContractResolver;
 }
コード例 #28
0
 public ReferencedSchemaGenerator(SchemaGeneratorOptions options, ISchemaGenerator rootGenerator, IContractResolver contractResolver)
     : base(options, rootGenerator, contractResolver)
 {
 }
コード例 #29
0
 public SchemaGenerator(SchemaGeneratorOptions generatorOptions, ISerializerMetadataResolver serializerMetadataResolver)
 {
     _generatorOptions           = generatorOptions;
     _serializerMetadataResolver = serializerMetadataResolver;
 }
コード例 #30
0
 public ApiPrimitiveHandler(SchemaGeneratorOptions options, ISchemaGenerator generator)
     : base(options, generator)
 {
 }