Skip to content

Commit

Permalink
Merge branch 'feature/multi-arch-docker-images' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
saturna authored Sep 15, 2023
2 parents 596e801 + 91eda86 commit c489038
Show file tree
Hide file tree
Showing 65 changed files with 3,730 additions and 2,790 deletions.
19 changes: 4 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ version: 2.1
executors:
docker-node:
docker:
- image: circleci/node:16
- image: cimg/node:16.20.2
docker-harness:
docker:
- image: circleci/node:16
- image: cimg/node:16.20.2
- image: kennethreitz/httpbin
name: httpbin.org
macos:
macos:
xcode: 13.3.1

orbs:
stoplight: stoplight/[email protected]
xcode: 13.4.1
jobs:
build:
executor: docker-node
Expand Down Expand Up @@ -85,7 +82,7 @@ jobs:
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Publish
command: yarn lerna publish from-git --create-release=github --yes --no-verify-access
command: yarn lerna publish from-git --create-release=github --yes
- run:
name: Create CLI binaries
command: npx pkg --out-path ./cli-binaries ./packages/cli/
Expand Down Expand Up @@ -148,11 +145,3 @@ workflows:
only: /^v.*/
requires:
- publish
- stoplight/analyze:
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
requires:
- upload_artifacts
2 changes: 1 addition & 1 deletion .github/workflows/dockerhub-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
echo "TAG_PRIMARY_VERSION=$(release='${{github.event.release.tag_name}}' && echo ${release:1:1})" >> $GITHUB_ENV
echo "TAG_FULL_VERSION=$(release='${{github.event.release.tag_name}}' && echo ${release:1})" >> $GITHUB_ENV
-
name: Build and Push release Tags
name: Build and Push release tags
if: env.IS_RELEASE == 'true'
uses: docker/build-push-action@v4
with:
Expand Down
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

# Unreleased

- Limit the `sl-violations` response header to around 8kb. [#2297](https://github.com/stoplightio/prism/pull/2297)
# 5.3.1 (2023.08.25)

- fixed issue with validateOutput() when schema contains internal reference. [#2363](https://github.com/stoplightio/prism/pull/2363) - thanks @mtjandra for your contribution!

# 5.3.0 (2023.08.17)

- added new cli parameter to control the json schema faker fillProperties setting universally. [#2355](https://github.com/stoplightio/prism/pull/2355)
- correctly list Response or Request in violation messages. [#2358](https://github.com/stoplightio/prism/pull/2358)

# 5.2.0 (2023.07.28)

- added support for multipart/form-data in the request body. [#2321](https://github.com/stoplightio/prism/pull/2321) - thanks @ilanashapiro for your contribution!

# 5.1.0 (2023.07.24)

- Improved error messages when using static mocking and the schema is too complex.

# 5.0.1 (2023.06.01)

- Limit the `sl-violations` response header to around 8 KB. [#2297](https://github.com/stoplightio/prism/pull/2297)
- Improve error messages that describe unresolvable JSON Pointer references. [#2195](https://github.com/stoplightio/prism/issues/2195)

# 5.0.0 (2023.05.17)

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ This information refers to Open Source Prism 3.x, which is the current version m

### Install Self-hosted Prism

_Prism requires NodeJS >= 16 to properly work._
Prism requires
- NodeJS >= 16
- for NodeJS 18.x, [>= 18.16 is required](https://github.com/stoplightio/prism/issues/2305)

```bash
npm install -g @stoplight/prism-cli
Expand Down
37 changes: 29 additions & 8 deletions docs/guides/06-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All the errors that Prism returns conform to [RFC7807](https://tools.ietf.org/ht

This document enumerates all the possible errors returned by Prism and provides some further information on how to solve them.

## Routing errors
## Routing Errors

This class of errors is returned when Prism is trying to identify the right resource to use to respond to the provided HTTP Request.

Expand Down Expand Up @@ -136,7 +136,7 @@ paths:

**Explanation:** This error occurs when a base URL has been provided in the current request (enabling the server validation feature) but the current document doesn't have any `servers` field/entry.

## Validation errors
## Validation Errors

This class of errors is returned when Prism is validating the request/response against the provided OpenAPI file.

Expand Down Expand Up @@ -186,19 +186,25 @@ curl http://localhost:4010/todos -H "accept: application/json"`
**Returned Status Code: `404`**
**Explanation:** This error occurs when the current request is asking for a specific status code that the document isn't listing or it's asking for a specific example that doesn't exist in the current document
**Explanation:** This error occurs when the current request is asking for a specific status code that the document isn't listing or it's asking for a specific example that doesn't exist in the current document.
### VIOLATIONS
**Message: Request/Response not valid**
**Message #1: Request/Response not valid**
**Returned Status Code: `500`**
**Explanation:** This error occurs when you're run Prism with the `--errors` flag and the request or the response has at least one violation marked as an error
**Explanation:** This error occurs when you're run Prism with the `--errors` flag and the request or the response has at least one violation marked as an error.
**Message #2: response.body Request body must match exactly one schema in oneOf**
**Returned Status Code: N/A**
**Explanation:** This error can occur if the current document contains a [discriminator](https://spec.openapis.org/oas/v3.0.1.html#discriminator-object). Prism does not support discriminators.
---
## Security errors
## Security Errors
This class of errors is returned when the current request isn't satisfying the security requirements specified in the current resource
Expand All @@ -212,7 +218,7 @@ This class of errors is returned when the current request isn't satisfying the s
---
## Negotiation errors
## Negotiation Errors
This class of errors is returned when anything goes wrong between your **valid** request and returning a suitable response
Expand Down Expand Up @@ -264,6 +270,21 @@ paths:

**Explanation:** This error occurs when the current request specifies a `Content-Type` that isn't supported by corresponding HTTP Operation. In the case there is no request body or `Content-Length` is 0, the `Content-Type` header is ignored.

## Unknown error

### SCHEMA_TOO_COMPLEX

**Message: Unable to generate [body|header] for response. The schema is too complex to generate.**

**Returned Status Code: `500`**

**Explanation:** This error occurs when part of the response can't be generated using JSON Schema Sampler. JSON Schema Sampler has been configured to use a limit of 2500 "ticks". A "tick" is loosely defined as any instance of a JSON Schema schema or subschema. This includes a/an single:
* Property
* Object
* Array item (each in an array between `minItems` and `maxItems`, defaulting to 1)
* Combiner item (members of `allOf`, `oneOf`, `anyOf`)

...all recursively, unless a `$ref` has already been visited (in which case, the subschema is skipped). As a workaround, consider using [dynamic response mocking](./11-dynamic-response-with-faker.md).

## Unknown Error

In case you get an `UNKNOWN` error, it likely means this particular edge case isn't handled. If you encounter one of these, open an [issue](https://github.com/stoplightio/prism/issues/new?labels=bug&template=bug_report.md).
17 changes: 17 additions & 0 deletions docs/guides/11-dynamic-response-with-faker.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,21 @@ x-json-schema-faker:
max-items: 10
optionalsProbability: 0.5
resolve-json-path: true
```

### Fill or Additional Properties

By default, `fillProperties` (*additional properties* in OpenAPI) are enabled. When `fillProperties = true`, the JSON Schema Faker generates missing properties to fulfill the schema definition.

To set `fillProperties` to `false`, use one of the following options:

- **CLI:** Run `prism mock -d --json-schema-faker-fillProperties=false api.oas3.yaml`. Setting this value with the CLI takes priority over the value set in `x-json-schema-faker`
- **Schema:** Add a `x-json-schema-faker` object at the top level of your schema.

```yaml
openapi: 3.1.0
x-json-schema-faker:
min-items: 2
max-items: 3
fillproperties: false
```
10 changes: 4 additions & 6 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"packages": [
"packages/*"
],
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "5.0.0",
"independent": false
"version": "5.3.1",
"independent": false,
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@stoplight/types": "^13.15.0",
"@types/caseless": "^0.12.2",
"@types/content-type": "^1.1.5",
"@types/faker": "^6.6.9",
"@types/jest": "^27.0.2",
"@types/json-schema": "^7.0.9",
"@types/lodash": "^4.14.175",
Expand All @@ -42,6 +41,7 @@
"@types/type-is": "^1.6.3",
"@types/uri-template-lite": "^19.12.1",
"@types/urijs": "^1.19.17",
"@types/whatwg-mimetype": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^4.33.0",
"abstract-logging": "^2.0.1",
Expand All @@ -50,12 +50,13 @@
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^4.2.1",
"fast-xml-parser": "^4.2.0",
"form-data": "^4.0.0",
"gavel": "^10.0.3",
"glob": "^7.2.0",
"http-string-parser": "^0.0.6",
"husky": "^8.0.1",
"jest": "^27.2.5",
"lerna": "~5.4.3",
"lerna": "~7.1.5",
"lint-staged": "^10.5.4",
"lodash": "^4.17.21",
"nock": "^13.1.3",
Expand All @@ -67,7 +68,7 @@
"ts-node": "^9.1.1",
"ts-transform-import-path-rewrite": "^0.3.0",
"tsconfig-paths": "^4.1.0",
"ttypescript": "^1.5.13",
"ttypescript": "^1.5.15",
"type-is": "^1.6.18",
"typescript": "4.9.3"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/prism-cli",
"version": "5.0.0",
"version": "5.3.1",
"author": "Stoplight <[email protected]>",
"bin": {
"prism": "./dist/index.js"
Expand All @@ -9,10 +9,10 @@
"dependencies": {
"@stoplight/http-spec": "^5.9.2",
"@stoplight/json": "^3.18.1",
"@stoplight/json-schema-ref-parser": "9.2.4",
"@stoplight/prism-core": "^5.0.0",
"@stoplight/prism-http": "^5.0.0",
"@stoplight/prism-http-server": "^5.0.0",
"@stoplight/json-schema-ref-parser": "9.2.5",
"@stoplight/prism-core": "^5.3.1",
"@stoplight/prism-http": "^5.3.1",
"@stoplight/prism-http-server": "^5.3.1",
"@stoplight/types": "^13.15.0",
"chalk": "^4.1.2",
"chokidar": "^3.5.2",
Expand Down
20 changes: 18 additions & 2 deletions packages/cli/src/commands/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,29 @@ const mockCommand: CommandModule = {
boolean: true,
default: false,
},
'json-schema-faker-fillProperties': {
description: 'Generate additional properties when using dynamic generation.',
default: undefined,
boolean: true,
},
}),
handler: parsedArgs => {
const { multiprocess, dynamic, port, host, cors, document, errors, verboseLevel } =
parsedArgs.jsonSchemaFakerFillProperties = parsedArgs['json-schema-faker-fillProperties'];
const { multiprocess, dynamic, port, host, cors, document, errors, verboseLevel, jsonSchemaFakerFillProperties } =
parsedArgs as unknown as CreateMockServerOptions;

const createPrism = multiprocess ? createMultiProcessPrism : createSingleProcessPrism;
const options = { cors, dynamic, port, host, document, multiprocess, errors, verboseLevel };
const options = {
cors,
dynamic,
port,
host,
document,
multiprocess,
errors,
verboseLevel,
jsonSchemaFakerFillProperties,
};

return runPrismAndSetupWatcher(createPrism, options);
},
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const proxyCommand: CommandModule = {
'errors',
'validateRequest',
'verboseLevel',
'upstreamProxy'
'upstreamProxy',
'jsonSchemaFakerFillProperties'
);

const createPrism = p.multiprocess ? createMultiProcessPrism : createSingleProcessPrism;
Expand Down
27 changes: 20 additions & 7 deletions packages/cli/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@ import * as JSONSchemaFaker from 'json-schema-faker';
import type { JSONSchemaFakerOptions } from 'json-schema-faker';
import { resetJSONSchemaGenerator } from '@stoplight/prism-http';

export async function configureExtensionsFromSpec(specFilePathOrObject: string | object): Promise<void> {
export async function configureExtensionsUserProvided(
specFilePathOrObject: string | object,
cliParamOptions: { [option: string]: any }
): Promise<void> {
const result = decycle(await new $RefParser().dereference(specFilePathOrObject));

resetJSONSchemaGenerator();

forOwn(get(result, 'x-json-schema-faker', {}), (value: any, option: string) => {
if (option === 'locale') {
// necessary as workaround broken types in json-schema-faker
// @ts-ignore
return JSONSchemaFaker.locate('faker').setLocale(value);
setFakerValue(option, value);
});

// cli parameter takes precidence, so it is set after spec extensions are configed
for (const param in cliParamOptions) {
if (cliParamOptions[param] !== undefined) {
setFakerValue(param, cliParamOptions[param]);
}
}
}

function setFakerValue(option: string, value: any) {
if (option === 'locale') {
// necessary as workaround broken types in json-schema-faker
// @ts-ignore
JSONSchemaFaker.option(camelCase(option) as keyof JSONSchemaFakerOptions, value);
});
return JSONSchemaFaker.locate('faker').setLocale(value);
}
// necessary as workaround broken types in json-schema-faker
// @ts-ignore
JSONSchemaFaker.option(camelCase(option) as keyof JSONSchemaFakerOptions, value);
}
11 changes: 9 additions & 2 deletions packages/cli/src/util/createServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createExamplePath } from './paths';
import { attachTagsToParamsValues, transformPathParamsValues } from './colorizer';
import { CreatePrism } from './runner';
import { getHttpOperationsFromSpec } from '../operations';
import { configureExtensionsFromSpec } from '../extensions';
import { configureExtensionsUserProvided } from '../extensions';

type PrismLogDescriptor = pino.LogDescriptor & {
name: keyof typeof LOG_COLOR_MAP;
Expand Down Expand Up @@ -71,7 +71,10 @@ const createSingleProcessPrism: CreatePrism = options => {

async function createPrismServerWithLogger(options: CreateBaseServerOptions, logInstance: pino.Logger) {
const operations = await getHttpOperationsFromSpec(options.document);
await configureExtensionsFromSpec(options.document);
const jsonSchemaFakerCliParams: { [option: string]: any } = {
['fillProperties']: options.jsonSchemaFakerFillProperties,
};
await configureExtensionsUserProvided(options.document, jsonSchemaFakerCliParams);

if (operations.length === 0) {
throw new Error('No operations found in the current file.');
Expand Down Expand Up @@ -140,6 +143,9 @@ function isProxyServerOptions(options: CreateBaseServerOptions): options is Crea
return 'upstream' in options;
}

/**
* @property {boolean} jsonSchemaFakerFillProperties - Used to override the default json-schema-faker extension value
*/
type CreateBaseServerOptions = {
dynamic: boolean;
cors: boolean;
Expand All @@ -149,6 +155,7 @@ type CreateBaseServerOptions = {
multiprocess: boolean;
errors: boolean;
verboseLevel: string;
jsonSchemaFakerFillProperties: boolean;
};

export interface CreateProxyServerOptions extends CreateBaseServerOptions {
Expand Down
Loading

0 comments on commit c489038

Please sign in to comment.