Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
97 stars 45 forks source link

backslash not handled #196

Closed dickermoshe closed 7 months ago

dickermoshe commented 7 months ago
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, unused_import

import 'package:freezed_annotation/freezed_annotation.dart';

part 'special_characters.freezed.dart';
part 'special_characters.g.dart';

/// description
@Freezed()
class SpecialCharacters with _$SpecialCharacters {
  const factory SpecialCharacters({
    /// double quote.
    /// Incorrect name has been replaced. Original name: `"`.
    @JsonKey(name: '"')
    required String object1,

    /// backslash.
    /// Incorrect name has been replaced. Original name: `\`.
    @JsonKey(name: '\')
    required String object2,
  }) = _SpecialCharacters;

  factory SpecialCharacters.fromJson(Map<String, Object?> json) => _$SpecialCharactersFromJson(json);
}

Schema:

openapi: 3.0.3
info:
  description: test
  version: 1.0.0
  title: test
paths:
  /test:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MySchemaName._-Characters'
      responses:
        '200':
          description: the response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MySchemaName._-Characters'
components:
  schemas:
    Parent:
      properties:
        objectType:
          type: string
      discriminator:
        propertyName: objectType
    ChildSchema:
      description: A schema that does not have any special character.
      allOf:
        - $ref: '#/components/schemas/Parent'
        - type: object
          properties:
            prop1:
              type: string
    # Note: the name below with non-ASCII characters is a valid JSON schema name,
    # however currently OpenAPI generator does not allow special characters beyond [.-_]
    #
    # The set of allowed characters for OpenAPI schema names is specified in RFC 8259
    # at https://tools.ietf.org/html/rfc8259.
    # The OpenAPI schema uses the JSON schema specification, which references RFC 8259.
    # A string is a sequence of zero or more Unicode characters [UNICODE].
    # Note that this citation references the latest version of Unicode
    # rather than a specific release. Any character may be escaped.
    # MySchemaNameWithUnusual#$12.3!@#%๐Ÿ‡๐Ÿ…๐Ÿ˜€๐Ÿ„๐Ÿพโ€โ™‚๏ธCharacters:
    MySchemaName._-Characters:
      description:
        A schema name that has letters, numbers, punctuation and non-ASCII characters.
        The sanitization rules should make it possible to generate a language-specific
        classname with allowed characters in that programming language. 
      allOf:
        - $ref: '#/components/schemas/Parent'
        - type: object
          properties:
            prop2:
              type: string
    # Below is a schema with the same name, except special characters have been removed.
    # This causes a codegen issue because the generated code will have exactly the same class name
    # as the above 'MySchemaName._-Characters'.
    # Hence the schema is commented out for now.
    #
    #MySchemaNameCharacters:
    #  description:
    #    A schema with same name as above, without the special characters. 
    #  allOf:
    #    - $ref: '#/components/schemas/Parent'
    #    - type: object
    #      properties:
    #        prop2:
    #          type: string
dickermoshe commented 7 months ago

@Carapacik This must be the wrong schema. It works now