module Sbuilder require_relative 'cli-text' class CliPet # ------------------------------------------------------------------ # Constans FILE_RESOLVER_PETSTORE="resolver_petstore.yaml" FILE_RESOLVER_PETSTORE_DEFAULT="resolver_petstore_default.yaml" FILE_INFRASTRUCTURE_PETSTORE="petstore-infra.yaml" FILE_INTERFACE_TAGS="petstore-tags.yaml" FILE_EXTENSIONS_PETSTORE_COMMON="extend_petstore_doms.yaml" FILE_EXTENSIONS_PETSTORE_RUN1="extend_petstore_run1.yaml" FILE_EXTENSIONS_PETSTORE_RUN2="extend_petstore_run2.yaml" FILE_EXTENSIONS_PETSTORE_RUN3="extend_petstore_run3.yaml" FILE_EXTENSIONS_PETSTORE_RUN_SVG="extend_petstore_run_svg.yaml" PETSTORE_URL="https://cdn.rawgit.com/swagger-api/swagger-spec/master/examples/v2.0/yaml/petstore-expanded.yaml" # ------------------------------------------------------------------ # sbuilder SBUILDER_YAML_PET= <<-EOS # sbuilder.ymal - for pet example # # ------------------------------------------------------------------ #{Sbuilder::CliText::SBUILDER_EXTENSION} extend: loaders: - className: Sbuilder::SnippetLoaderSimple configuration: src_dir: src/pet # ------------------------------------------------------------------ #{Sbuilder::CliText::SBUILBER_INTERFACES} interfaces: - className: Sbuilder::ParamSetLoaderSwagger url: #{PETSTORE_URL} cache: petstore.yaml - className: Sbuilder::ParamSetLoaderSwagger file: #{FILE_INTERFACE_TAGS} - className: Sbuilder::ParamSetLoaderSwagger infrastructureServices: true file: #{FILE_INFRASTRUCTURE_PETSTORE} # ------------------------------------------------------------------ #{Sbuilder::CliText::SBUILDER_SNIPPETS} snippets: - className: Sbuilder::SnippetLoaderSimple snippets: - metatype: service_implementation appName: /pets(post) file: interface_post_pet.tla - metatype: service_implementation appName: /pets/{id}(delete) file: interface_delete_pet.tla - metatype: service_implementation appName: /pets/{id}(get) file: interface_get_pet.tla - metatype: service_implementation appName: /tags(post) file: interface_post_tag.tla - metatype: service_implementation appName: /tags(put) file: interface_put_tag.tla # ------------------------------------------------------------------ #{Sbuilder::CliText::SBUILDER_RESOLVERS} resolvers: - url: cnf/#{FILE_RESOLVER_PETSTORE} # un-comment to use default resolver. # normally not used # - type: resolver_yaml # url: cnf/#{FILE_RESOLVER_PETSTORE_DEFAULT} # ------------------------------------------------------------------ #{Sbuilder::CliText::SBUILER_SETUPS} setups: - setupDirectory: default desc: Validate assumptions assumptions: - Assume_Address_Domains - Assume_Id_Domains - Assume_Tag_Domains - Assume_Owner_Domains - Assume_Pet_Domains - setupDirectory: pet1 extensions: - url: cnf/#{FILE_EXTENSIONS_PETSTORE_COMMON} - url: cnf/#{FILE_EXTENSIONS_PETSTORE_RUN1} possibilities: - tag_with_invalid_address - at_least_two_tags - setupDirectory: pet2 extensions: - url: cnf/#{FILE_EXTENSIONS_PETSTORE_COMMON} - url: cnf/#{FILE_EXTENSIONS_PETSTORE_RUN2} - setupDirectory: pet3 extensions: - url: cnf/#{FILE_EXTENSIONS_PETSTORE_COMMON} - url: cnf/#{FILE_EXTENSIONS_PETSTORE_RUN3} possibilities: - tag_with_invalid_address - at_least_two_tags - setupDirectory: pet-svg extensions: - url: cnf/#{FILE_EXTENSIONS_PETSTORE_COMMON} - url: cnf/#{FILE_EXTENSIONS_PETSTORE_RUN_SVG} - setupDirectory: error-invalidate-name desc: Owner name is invalidate on a tag referenced preferences: error-invalidate-name: true extensions: - url: cnf/#{FILE_EXTENSIONS_PETSTORE_COMMON} - url: cnf/#{FILE_EXTENSIONS_PETSTORE_RUN3} - setupDirectory: error-duplicate-tag desc: Duplicate tag violation found preferences: error-duplicate-tag: true extensions: - url: cnf/#{FILE_EXTENSIONS_PETSTORE_COMMON} - url: cnf/#{FILE_EXTENSIONS_PETSTORE_RUN3} # ------------------------------------------------------------------ #{Sbuilder::CliText::SBUILDER_PREFERENCES} preferences: debug-output: true # ------------------------------------------------------------------ #{Sbuilder::CliText::SBUILDER_GENERATE} generate: - output: doc/tag-put.md inputs: - desc: Implementation of tag put modelData: none template: markdown-toc.mustache - desc: Service "put_tag" modelData: none template: markdown-header.mustache templateParameters: include: service_tag_put.tla - desc: Operator "GetTagtByIdentity" modelData: none template: markdown-header.mustache templateParameters: include: operator_get_tag.tla - desc: Operator "ValidateTagData" modelData: none template: markdown-header.mustache templateParameters: include: operator_valid_tag.tla - desc: Operator "TagReferenced" modelData: none template: markdown-header.mustache templateParameters: include: operator_tag_referenced.tla - desc: Operator "TagOwnerValidated" modelData: none template: markdown-header.mustache templateParameters: include: operator_tag_owner_validated.tla - desc: Transaction "enter_tag" modelData: none template: markdown-header.mustache templateParameters: include: transaction_enter_tag.tla - desc: Tag owner address coherence modelData: none template: markdown-header.mustache templateParameters: include: correctness_coherent_owner_address.tla - desc: Pet tag reference integrity modelData: none template: markdown-header.mustache templateParameters: include: correctness_ref_tag.tla - desc: Tag uniqueness modelData: none template: markdown-header.mustache templateParameters: include: correctness_unique_tag.tla - output: doc/tag-post.md inputs: - desc: Implementation of tag post modelData: none template: markdown-toc.mustache - desc: Service tag-post modelData: none template: markdown-header.mustache templateParameters: include: service_tag_put.tla - desc: Operator "ValidateTagData" modelData: none template: markdown-header.mustache templateParameters: include: operator_valid_tag.tla - desc: Operator "TagOwnerValidated" modelData: none template: markdown-header.mustache templateParameters: include: operator_tag_owner_validated.tla - desc: Operator "ValidOwner" modelData: none template: markdown-header.mustache templateParameters: include: operator_valid_owner.tla - desc: Transaction modelData: none template: markdown-header.mustache templateParameters: include: transaction_enter_tag.tla - output: doc/pet-post.md inputs: - desc: Implementation of pet post modelData: none template: markdown-toc.mustache - desc: Pet post service modelData: none template: markdown-header.mustache templateParameters: include: service_pet_post.tla - desc: Operator "ValidatePetData" modelData: none template: markdown-header.mustache templateParameters: include: operator_valid_pet.tla - desc: Operator "ValidTagExists" modelData: none template: markdown-header.mustache templateParameters: include: operator_tag_exists.tla - desc: Enter pet into database modelData: none template: markdown-header.mustache templateParameters: include: transaction_enter_pet.tla - desc: Type invariant for Petstore modelData: none template: markdown-header.mustache templateParameters: include: correctness_pet_name.tla - desc: Tag owner address coherence modelData: none template: markdown-header.mustache templateParameters: include: correctness_coherent_owner_address.tla - desc: Pet tag reference integrity modelData: none template: markdown-header.mustache templateParameters: include: correctness_ref_tag.tla - desc: Tag uniqueness modelData: none template: markdown-header.mustache templateParameters: include: correctness_unique_tag.tla # - desc: Data for petstore # modelData: none # template: markdown-header.mustache # templateParameters: # include: state_pet.tla # - desc: Type definitions in Petstore # modelData: definitions # template: markdown-header.mustache # templateParameters: # include: definition_types.mustache #{Sbuilder::CliText::SBUILDER_INVARIANTS} invariants: - ValidatePets: All pet entries are valid - UniquePet: Pet id is unique - UniqueTag: Tag id is unique - ValidReferecendTag: For all pets there exists a unique, valid tag entry. - CoherentOwnerAddress: Address on all tags with the same ower are equal - Pets_TypeInvariant: Type invariant Pet - Tags_TypeInvariant: Type invariant Tag EOS EXTENSIONS_PETSTORE_COMMON = <<-EOS #{Sbuilder::CliText::EXTENSION_HEADER_PREFS} #{Sbuilder::CliText::EXTENSION_HEADER_DOM} # # Extend domain resolved in #{FILE_RESOLVER_PETSTORE} # - domain-extension: - domain: id cardinality: 3 - domain: pet_name cardinality: 3 - domain: error_codes values: - validation-error - unspecified #{Sbuilder::CliText::EXTENSION_HEADER_SETUP} # - interface-extension: # - matcher: /pets(post) # implementation: post_pet # - matcher: /pets/{id}(delete) # implementation: delete_pet # - matcher: /pets/{id}(get) # implementation: get_pet # - matcher: /tags(post) # implementation: post_tag # - matcher: /tags(put) # implementation: put_tag EOS EXTENSIONS_PETSTORE_RUN1 = <<-EOS #{Sbuilder::CliText::EXTENSION_HEADER_PREFS} #{Sbuilder::CliText::EXTENSION_HEADER_SETUP} # - step-extension: - interface: /pets(post) input: pet: name: 1 - interface: /pets(post) input: pet: name: 0 - interface: /pets/{id}(get) input: id: 1 - interface: /pets/{id}(delete) input: id: 1 - interface: /pets/{id}(get) input: id: 1 EOS EXTENSIONS_PETSTORE_RUN2 = <<-EOS #{Sbuilder::CliText::EXTENSION_HEADER_PREFS} # # - step-extension: - interface: /pets(post) - interface: /pets/{id}(get) - interface: /pets/{id}(delete) - interface: /pets/{id}(get) EOS EXTENSIONS_PETSTORE_RUN_SVG = <<-EOS #{Sbuilder::CliText::EXTENSION_HEADER_PREFS} # # Just enough behaviour to create a decent graph # - step-extension: - interface: /tags(post) # bindExact: true # inputs: # - input: # tag: # _default: 1 # name: 1 # - input: # tag: # _default: 2 # name: 1 # address: # _default: 1 - interface: /pets(post) bindExact: true inputs: - input: pet: _default: 1 tag: 1 - input: pet: _default: 1 tag: 0 - input: pet: _default: 1 tag: 2 - input: pet: _default: 1 tag: 3 - input: pet: _default: 1 tag: 2 # - input: # pet: # _default: 2 # - interface: /pets(post) # bindExact: true # inputs: # - input: # pet: # _default: 1 # # - input: # # pet: # # _default: 2 EOS EXTENSIONS_PETSTORE_RUN3 = <<-EOS #{Sbuilder::CliText::EXTENSION_HEADER_PREFS} # # - step-extension: - interface: /tags(post) - interface: /pets(post) - interface: /pets(post) bindExact: true inputs: - input: pet: _default: 1 - input: pet: _default: 2 - interface: /tags(post) input: tag: name: 1 address: street: 1 - interface: /pets(post) bindExact: true inputs: - input: pet: _default: 1 - input: pet: _default: 2 - interface: /tags(put) EOS RESOLVER_PETSTORE_DEFAULT = <<-EOS #{Sbuilder::CliText::RESOLVER_HEADER} # Default 'catch-all' resolver used for testing # # NOTICE: un-comment in sbuilder.yaml - Name: default-relsolver Matcher: !ruby/regexp /.*/ Rules: - Matcher: !ruby/regexp /.*/ Domain: default_domain EOS RESOLVER_PETSTORE = <<-EOS #{Sbuilder::CliText::RESOLVER_HEADER} # # Example mapper to Petstore example # see #{PETSTORE_URL} # Catch all rule - Name: pets_default Rules: - Matcher: !ruby/regexp /.*/ Domain: default # Definitions - Name: Error Matcher: Error Rules: - Matcher: code Domain: error_codes - Ref: pets_default # - Name: Status # Matcher: Status # Rules: # - Matcher: code # Domain: error_codes # - Ref: pets_default - Name: Address Matcher: Address Rules: - Matcher: street Domain: street - Matcher: city Domain: city # - Ref: pets_default - Name: Tag Matcher: Tag Rules: - Matcher: tag Domain: id - Name: Owner Matcher: Owner Rules: - Matcher: name Domain: owner_name - Name: Pet Matcher: Pet Rules: - Matcher: id Domain: id - Matcher: name Domain: pet_name - Matcher: tag Domain: id - Name: NewPet Matcher: NewPet Rules: - Ref: Pet - Name: Id-definition Matcher: Id Rules: - Matcher: id Domain: id # operations - Name: pets_get Matcher: /pets(get) Rules: - Matcher: tags Domain: pet_tags - Ref: pets_default - Name: pets_post Matcher: /pets(post) Rules: - Ref: Pet - Ref: Tag - Name: pets_get_id Matcher: /pets/{id}(get) Rules: - Ref: Pet - Name: pets_delete_id Matcher: /pets/{id}(delete) Rules: - Ref: Pet - Name: id_type_get Matcher: /id/{type}(get) Rules: - Ref: pets_default - Name: tags_post Matcher: /tags(post) Rules: - Ref: Owner - Name: tags_put Matcher: /tags(put) EOS INTERFACE_TAGS = <<-EOS # Additional services for Petstore # swagger: "2.0" info: version: 1.0.0 title: Petstore extensions description: A simple API for composite services termsOfService: http://swagger.io/terms/ contact: name: TLA Sbuilder team email: foo@example.com url: http://localhost license: name: MIT url: http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT host: locahost basePath: /api schemes: - http consumes: - application/json produces: - application/json paths: /tags: post: description: Creates a tag entry parameters: - name: tag in: body description: Tag to add required: true schema: $ref: '#/definitions/Owner' responses: 200: description: OK schema: $ref: '#/definitions/Tag' default: description: default put: description: Updates parameters: - name: tag in: body description: Tag to add required: true schema: $ref: '#/definitions/Tag' responses: 200: description: OK schema: $ref: '#/definitions/Tag' default: description: Some error schema: $ref: '#/definitions/Error' definitions: Tag: required: - tag properties: tag: type: string owner: $ref: '#/definitions/Owner' Owner: properties: name: type: string address: $ref: '#/definitions/Address' Address: properties: street: type: string city: type: string EOS INFRASTRUCTURE_PETSTORE = <<-EOS # Infrastrcuture services for Petstore # swagger: "2.0" info: version: 1.0.0 title: Petstore extensions description: A simple API for composite services termsOfService: http://swagger.io/terms/ contact: name: TLA Sbuilder team email: foo@example.com url: http://localhost license: name: MIT url: http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT host: locahost basePath: /api schemes: - http consumes: - application/json produces: - application/json paths: /id/{type}: get: operationId: Generate id from sequence {type} responses: 200: description: OK schema: $ref: '#/definitions/Id' 404: description: Could not generate id schema: $ref: '#/definitions/Error' definitions: Id: required: - id properties: id: type: string EOS class << self def write_files( dir, cli ) sbuilder_yaml = Sbuilder::Constants::CNF_FILE cli.write_example( dir, sbuilder_yaml, Sbuilder::CliPet::SBUILDER_YAML_PET ) cli.write_example( dir, Sbuilder::CliPet::FILE_RESOLVER_PETSTORE, Sbuilder::CliPet::RESOLVER_PETSTORE ) cli.write_example( dir, Sbuilder::CliPet::FILE_RESOLVER_PETSTORE_DEFAULT, Sbuilder::CliPet::RESOLVER_PETSTORE_DEFAULT ) cli.write_example( dir, Sbuilder::CliPet::FILE_INFRASTRUCTURE_PETSTORE, Sbuilder::CliPet::INFRASTRUCTURE_PETSTORE ) cli.write_example( dir, Sbuilder::CliPet::FILE_INTERFACE_TAGS, Sbuilder::CliPet::INTERFACE_TAGS ) cli.write_example( dir, Sbuilder::CliPet::FILE_EXTENSIONS_PETSTORE_COMMON, Sbuilder::CliPet::EXTENSIONS_PETSTORE_COMMON ) cli.write_example( dir, Sbuilder::CliPet::FILE_EXTENSIONS_PETSTORE_RUN1, Sbuilder::CliPet::EXTENSIONS_PETSTORE_RUN1 ) cli.write_example( dir, Sbuilder::CliPet::FILE_EXTENSIONS_PETSTORE_RUN2, Sbuilder::CliPet::EXTENSIONS_PETSTORE_RUN2 ) cli.write_example( dir, Sbuilder::CliPet::FILE_EXTENSIONS_PETSTORE_RUN3, Sbuilder::CliPet::EXTENSIONS_PETSTORE_RUN3 ) cli.write_example( dir, Sbuilder::CliPet::FILE_EXTENSIONS_PETSTORE_RUN_SVG, Sbuilder::CliPet::EXTENSIONS_PETSTORE_RUN_SVG ) end end end end