Class: Sbuilder::CliCustomer

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/cli-customer.rb

Constant Summary collapse

FILE_RESOLVER_CUSTOMER =
"resolver_customer.yaml"
FILE_INTERFACE_CUSTOMER =
"interface_customer.yaml"
FILE_EXTENSIONS_CUSTOMER_COMMON =
"extend_customer_doms.yaml"
FILE_EXTENSIONS_CUSTOMER_IF =
"extend_customer_if.yaml"
FILE_EXTENSIONS_CUSTOMER_RUN1 =
"extend_customer_run1.yaml"
FILE_EXTENSIONS_CUSTOMER_RUN2 =
"extend_customer_run2.yaml"
SBUILDER_YAML_CUSTOMER =
<<-EOS.unindent

# ------------------------------------------------------------------
#{Sbuilder::CliText::SBUILDER_PREFERENCES}
preferences:
      debug-output: true

# ------------------------------------------------------------------
#{Sbuilder::CliText::SBUILDER_EXTENSION}

# ------------------------------------------------------------------
#{Sbuilder::CliText::SBUILDER_SNIPPETS}

snippets:

  - className: Sbuilder::SnippetLoaderSimple 
    snippets:

        # make /customer(post) to map to name 'dummy'
      - metatype: service_implementation
        appName: /customers(post)
        name: dummy

# ------------------------------------------------------------------
#{Sbuilder::CliText::SBUILBER_INTERFACES}

interfaces:
    -  
       className: Sbuilder::ParamSetLoaderSwagger
       file: #{FILE_INTERFACE_CUSTOMER}


# ------------------------------------------------------------------
#{Sbuilder::CliText::SBUILDER_RESOLVERS}
resolvers:
     - file: #{FILE_RESOLVER_CUSTOMER}

# ------------------------------------------------------------------
#{Sbuilder::CliText::SBUILER_SETUPS}
setups:
    - setupDirectory: default

    - setupDirectory: customer1
      extensions:
        -  url: cnf/#{FILE_EXTENSIONS_CUSTOMER_COMMON}
        -  url: cnf/#{FILE_EXTENSIONS_CUSTOMER_IF}
        -  url: cnf/#{FILE_EXTENSIONS_CUSTOMER_RUN1}

    - setupDirectory: customer2
      extensions:
        -  url: cnf/#{FILE_EXTENSIONS_CUSTOMER_COMMON}
        -  url: cnf/#{FILE_EXTENSIONS_CUSTOMER_IF}
        -  url: cnf/#{FILE_EXTENSIONS_CUSTOMER_RUN2}

# ------------------------------------------------------------------

#{Sbuilder::CliText::SBUILDER_GENERATE}


# ------------------------------------------------------------------

#{Sbuilder::CliText::SBUILDER_INVARIANTS}
invariants:
    # - Invariant1: Add TLA operator definition Invariant1 and uncomment this line


EOS
EXTENSIONS_CUSTOMER_COMMON =
<<-EOS.unindent
#{Sbuilder::CliText::EXTENSION_HEADER_DOM}
#
#
- 
  domain-extension:
       - domain: customer_id
         cardinality: 2
       - domain: customer_type
         values:
              - business
              - consumer
       - domain: customer_name
         cardinality: 2
       - domain: customer_street
         cardinality: 1
       - domain: customer_city
         cardinality: 1

EOS
EXTENSIONS_CUSTOMER_IF =
<<-EOS.unindent

#{Sbuilder::CliText::EXTENSION_HEADER_PREFS}

#{Sbuilder::CliText::EXTENSION_HEADER_IF}
#
# 
# Exampl uses dummy process, which should be replaced with real implementation
#
# DEPRECATED: use snippets property in sbuilder.yaml
# 
# - interface-extension:
#       - matcher: /customers(post)
#         implementation: dummy
# 
EOS
EXTENSIONS_CUSTOMER_RUN1 =
<<-EOS.unindent
#{Sbuilder::CliText::EXTENSION_HEADER_SETUP}
#
# Extend domain resolved in #{FILE_RESOLVER_CUSTOMER} 
#
- step-extension:

       - interface: /customers(post)
         bindExact: true
         inputs:
            - input:
                customers:
                  - 
                    id: 1
                    type: business
                    _default: 1
                    address:
                      _default: 1
                  - 
                    id: 2
                    _default: 1
                    address:
                      _default: Nil

            - input:
                customers:
                  - 
                    id: 1
                    type: consumer
                    _default: 1
                    address:
                      _default: 1
                  - 
                    id: 2
                    _default: 1
                    address:
                      _default: 1

            - input:
                customers:
                  - 
                    id: 1
                    type: business
                    _default: 1
                    address:
                      _default: 1
                  - 
                    id: 2
                    _default: 1
                    address:
                      _default: 1

       # - interface: /customers(post)
       #   bindExact: true
       #   input:
       #          customers:
       #            - id: 1
       #              _default: 1
       #              address:
       #                _default: Nil

       # - interface: /customers(post)
       #   bindExact: true
       #   input:
       #          customers:
       #            - id: 1
       #              _default: Nil
       #              address:
       #                _default: Nil
       #            - id: 1
       #              _default: Nil
       #              address:
       #                _default: 1


       # - interface: /customers(post)
       #   input:
       #          # _default: 1
       #          customers:
       #            - id: 1
       #              # name: 1
       #            - id: 2
       #              # name: 2
       # #            - id: 3
       # #              name: 1

EOS
EXTENSIONS_CUSTOMER_RUN2 =
<<-EOS.unindent
#{Sbuilder::CliText::EXTENSION_HEADER_SETUP}
#
#
- step-extension:

       - interface: /customer(post)
         input:
            customer:
                # name: 2
                _default: 2
                address:
                   _default: Nil
                #    street: 1
                   # city: 1

       # - interface: /customers(post)
       #   input:
       #          # _default: 1
       #          customers:
       #            - id: 1
       #              # name: 1
       #            - id: 2



EOS
RESOLVER_CUSTOMER =
<<-EOS.unindent
#{Sbuilder::CliText::RESOLVER_HEADER}
#
# Example mapper for customer interface

-    Name: Customer
     Matcher: Customer
     Rules: 
      - Matcher: name
        Domain: customer_name

      - Matcher: id
        Domain: customer_id

      - Matcher: type
        Domain: customer_type

-    Name: Address
     Matcher: Address
     Rules: 
      - Matcher: street
        Domain: customer_street

      - Matcher: city
        Domain: customer_city


-    Name: Default
     Rules: 
      - Matcher: !ruby/regexp /.*/
        Domain: default

-    Name: Customers
     Matcher: Customers
     Rules: 
      - Ref: Customer



-    Name: customers_post
     Matcher: /customers(post)
     Rules: 
         - Ref: Customer

-    Name: Error
     Matcher: Error
     Rules: 
      - Matcher: code
        Domain: error_codes
      - Matcher: !ruby/regexp /.*/
        Domain: default


-    Name: customer_get
     Matcher: /customer(get)
     Rules: 
         - Ref: Customer
         - Ref: Default

-    Name: customer_post
     Matcher: /customer(post)
     Rules: 
         - Ref: Customer
         - Ref: Default

-    Name: customers_get
     Matcher: /customers(get)
     Rules: 
         - Matcher: names
           Domain: customer_name
         - Ref: Default


EOS
INTERFACE_CUSTOMER_SWAGGER =
<<-EOS.unindent
# Example YAML configuration file
# 
swagger: "2.0"
info:
  version: 1.0.0
  title: Sbuild demo customer
  description: A simple Customer API
  termsOfService: http://swagger.io/terms/
  contact:
    name: TLA Sbuilder team
    email: [email protected]
    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:
  /customer:
    get:
      operationId: findCustomers by id
      parameters:
        - name: id
          in: query
          description: tags to filter by
          required: false
          type: array
          collectionFormat: csv
          items:
            type: string
        - name: limit
          in: query
          description: maximum number of results to return
          required: false
          type: integer
          format: int32
      responses:
         200:
            description: OK
    post: 
      operationId: postCustomer
      parameters:
        - name: customer
          in: body
          description: Customers to enter
          required: true
          schema:
              $ref: '#/definitions/Customer'
      responses:
         200:
            description: OK
  /customers:
    post: 
      operationId: postCustomers
      parameters:
        - name: customers
          in: body
          description: Customers to enter
          required: true
          schema:
              $ref: '#/definitions/Customers'
      responses:
         200:
            description: OK
    get:
      operationId: findCustomers by tag
      parameters:
        - name: names
          in: query
          description: query by names
          required: false
          type: array
          collectionFormat: csv
          items:
            type: string
        - name: limit
          in: query
          description: maximum number of results to return
          required: false
          type: integer
          format: int32
      responses:
        200:
          description: customer response
          schema:
            type: array
            items:
              $ref: '#/definitions/Customer'
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/Error'
definitions:
       Address:
         properties:
           street:
            type: string
           city:
            type: string
       Customers:
            type: array
            allOf:
              - $ref: '#/definitions/Customer'
       Customer:
         properties:
           id:
            type: string
           type:
            type: string
           name:
            type: string
           address:
              $ref: '#/definitions/Address'
     
       Error:
         required:
           - code
           - message
         properties:
           code:
             type: integer
             format: int32
           message:
             type: string
EOS