diff --git a/.circleci/config.yml b/.circleci/config.yml index 6aa059842..78ac98828 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -82,6 +82,9 @@ jobs: name: Build all code to JavaScript command: yarn build - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + - run: + name: Publish on the beta tag + command: yarn lerna publish $(npx semver --preid beta -i prerelease $(npm show @stoplight/prism-cli@beta version)) --no-push --no-git-tag-version --dist-tag beta -y - run: name: Publish command: yarn lerna publish from-git --create-release=github --yes diff --git a/CHANGELOG.md b/CHANGELOG.md index 3005bdd0a..80d96721f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), # Unreleased +## Fixed + +- Prism is not returning an error anymore when trying to construct a schema for HTTP headers and query string with mixed cases property names [#1268](https://github.com/stoplightio/prism/pull/1268) + ## Changed - **BREAKING**: The `getHttpOperationsFromSpec` has been moved from the HTTP Package to the CLI package. If you're using Prism programmatically, this might require some code changes on your side. `getHttpOperationsFromResource` has been removed. [#1009](https://github.com/stoplightio/prism/pull/1009), [#1192](https://github.com/stoplightio/prism/pull/1192) diff --git a/package.json b/package.json index 3d2588c98..edc424b01 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,6 @@ "posttest": "yarn lint", "test": "jest", "release": "lerna version", - "prerelease:beta": "yarn build", - "release:beta": "lerna publish --preid beta --force-publish=* --no-push --no-git-tag-version --dist-tag beta", "prebuild.binary": "yarn build", "build.binary": "npx pkg --output ./cli-binaries/prism-cli ./packages/cli/", "test.harness": "jest -c ./jest.harness.config.js" diff --git a/packages/http/src/validator/validators/params.ts b/packages/http/src/validator/validators/params.ts index 76931fead..3f6175d6b 100644 --- a/packages/http/src/validator/validators/params.ts +++ b/packages/http/src/validator/validators/params.ts @@ -2,7 +2,7 @@ import { DiagnosticSeverity, HttpParamStyles, IHttpParam } from '@stoplight/type import { compact, keyBy, mapKeys, mapValues, pickBy, upperFirst } from 'lodash'; import * as E from 'fp-ts/lib/Either'; import * as O from 'fp-ts/lib/Option'; -import { fromArray } from 'fp-ts/lib/NonEmptyArray'; +import * as NEA from 'fp-ts/lib/NonEmptyArray'; import { pipe } from 'fp-ts/lib/pipeable'; import { JSONSchema4 } from 'json-schema'; import { JSONSchema } from '../../'; @@ -31,8 +31,9 @@ export class HttpParamsValidator implements IHttpValidator { + NEA.fromArray(specs), + O.map(specs => { + const schema = createJsonSchemaFromParams(specs); const parameterValues = pickBy( mapValues( keyBy(specs, s => s.name.toLowerCase()), @@ -47,7 +48,7 @@ export class HttpParamsValidator implements IHttpValidator key.toLowerCase()), - schema.properties && (schema.properties[el.name] as JSONSchema4), + schema.properties && (schema.properties[el.name.toLowerCase()] as JSONSchema4), el.explode || false ); @@ -59,26 +60,23 @@ export class HttpParamsValidator implements IHttpValidator validateAgainstSchema(parameterValues, schema, true, prefix)), O.map(schemaDiagnostic => schemaDiagnostic.concat(deprecatedWarnings)), - O.chain(fromArray), - O.alt(() => fromArray(deprecatedWarnings)), + O.chain(NEA.fromArray), + O.alt(() => NEA.fromArray(deprecatedWarnings)), E.fromOption(() => target), E.swap ); } } -function createJsonSchemaFromParams(params: IHttpParam[]): O.Option { - return pipe( - fromArray(params), - O.map(params => ({ - type: 'object', - properties: pickBy( - mapValues( - keyBy(params, p => p.name.toLowerCase()), - 'schema' - ) - ) as JSONSchema4, - required: compact(params.map(m => (m.required ? m.name.toLowerCase() : undefined))), - })) - ); +function createJsonSchemaFromParams(params: NEA.NonEmptyArray): JSONSchema { + return { + type: 'object', + properties: pickBy( + mapValues( + keyBy(params, p => p.name.toLocaleLowerCase()), + 'schema' + ) + ) as JSONSchema4, + required: compact(params.map(m => (m.required ? m.name.toLowerCase() : undefined))), + }; } diff --git a/test-harness/specs/validate-query-params/query-param-upper-case.oas2.txt b/test-harness/specs/validate-query-params/query-param-upper-case.oas2.txt new file mode 100644 index 000000000..c08a90de7 --- /dev/null +++ b/test-harness/specs/validate-query-params/query-param-upper-case.oas2.txt @@ -0,0 +1,32 @@ +====test==== +When I send a request to an operation +And the operation has a query param specified in mixed between lowercase and uppercase +And in the request I sent that param is present in a different casing +It should still pass the validation +====spec==== +swagger: '2.0' +produces: + - application/json +paths: + "/v1/test": + get: + parameters: + - collectionFormat: csv + in: query + items: + format: uuid + type: string + name: filter[somethingId] + required: false + type: array + responses: + '200': + description: OK + examples: + error: false +====server==== +mock -p 4010 ${document} +====command==== +curl -sIXGET http://127.0.0.1:4010/v1/test?somethingid=04fc0172-1943-4c38-8e0f-36935e05b8dd +====expect==== +HTTP/1.1 200 OK