Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Proposal: Generation API #126

Open
maxlinc opened this issue Jun 16, 2014 · 0 comments
Open

Proposal: Generation API #126

maxlinc opened this issue Jun 16, 2014 · 0 comments

Comments

@maxlinc
Copy link
Collaborator

maxlinc commented Jun 16, 2014

Continuing to think about new APIs that align with the Roadmap, here's how I think generation could be improved Roadmap.

The big advantage of current generation features is the ability to provide more generation hints. Giving a hint (via the service_manifest) for the URI template is especially useful, because it saves cleaning up the file names, URI templates, and de-duplicating contracts after generation.

This also provides some hints of what a Provider API may look like.

      Pacto.configuration.generation_hints do |hints|
        hints.generation_enabled = true
        hints.schema_version = :draft4
        hints.overwrite = false
        hints.save_examples = true
        hints.generate_defaults = false
      end

      Pacto.provider(:my_api) do
        service_manifest do
          # You can load existing services as-is:
          load_services 'contract/my_api/**/*.json'

          # However, providing an brief description of each service can provide useful generation hints
          # This isn't a full service contract - it's more like an index or table of contents...
          # but the info here can be useful hints for generation or reporting.

          service 'List Projects', :get, 'https://example.com/projects', file: 'contracts/list_projects.json'
          # This provides useful hints that we couldn't get from the HTTP interaction itself, like:
          #   - A nickname for the service
          #   - The URI template, which tells us about the id and sort variables (and prevents us from generating duplicate contracts)
          #   - A preferred location to store the contract, because the default would have been something like
          #       contracts/my_api/example.com/projects/{id}/put_{id}.json.
          #   - Note: the nickname alone might be enough to have better default locations, assuming names are unique
          #           at least within a provider.
          service 'Create or Update Project', :put, 'https://example.com/projects/{id}{?sort}', file: 'contracts/put_project.json'
          service 'Get Project', :get, 'https://example.com/projects/{id}', file: 'contracts/get_project.json'
        end

        # A manifest could probably be loaded via JSON or YAML rather than a block.
        service_manifest('providers/my_api/manifest.yaml')
      end

      # Execute tests as normal (by running real consumers or simulated consumers) in order to generate
@maxlinc maxlinc modified the milestones: v0.5.0, v0.4.0 Dec 19, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant