Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Usage:

Available Commands:
up Start live mocks of APIs
scaffold Create Imposter configuration from OpenAPI specs
scaffold Create Imposter configuration from OpenAPI specs and WSDL files
engine pull Pull the engine into the cache
engine list List the engines in the cache
doctor Check prerequisites for running Imposter
Expand Down Expand Up @@ -150,7 +150,7 @@ Flags:
-p, --port int Port on which to listen (default 8080)
--pull Force engine pull
-r, --recursive-config-scan Scan for config files in subdirectories (default false)
-s, --scaffold Scaffold Imposter configuration for all OpenAPI files
-s, --scaffold Scaffold Imposter configuration for all OpenAPI and WSDL files
-v, --version string Imposter engine version (default "latest")
```

Expand Down
7 changes: 4 additions & 3 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ var scaffoldCmd = &cobra.Command{
Aliases: []string{"init"},
Short: "Create Imposter configuration",
Long: `Creates Imposter configuration files. If one or more OpenAPI/Swagger
specification files are present, they are used as the basis for the generated
resources. If no specification files are present, a simple REST mock is created.
specification files or WSDL files are present, they are used as the basis for
the generated resources. If no specification files are present, a simple REST
mock is created.

If DIR is not specified, the current working directory is used.`,
Args: cobra.RangeArgs(0, 1),
Expand All @@ -54,7 +55,7 @@ If DIR is not specified, the current working directory is used.`,

func init() {
scaffoldCmd.Flags().BoolVarP(&scaffoldFlags.forceOverwrite, "force-overwrite", "f", false, "Force overwrite of destination file(s) if already exist")
scaffoldCmd.Flags().BoolVar(&scaffoldFlags.generateResources, "generate-resources", true, "Generate Imposter resources from OpenAPI paths")
scaffoldCmd.Flags().BoolVar(&scaffoldFlags.generateResources, "generate-resources", true, "Generate Imposter resources from OpenAPI paths or WSDL operations")
scaffoldCmd.Flags().StringVarP(&scaffoldFlags.scriptEngine, "script-engine", "s", "none", "Generate placeholder Imposter script (none|groovy|js)")
rootCmd.AddCommand(scaffoldCmd)
}
40 changes: 40 additions & 0 deletions cmd/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Test_createMockConfig(t *testing.T) {
forceOverwrite bool
scriptEngine impostermodel2.ScriptEngine
copySpecs bool
copyWsdl bool
anchorFileName string
checkResponseFile bool
}
Expand Down Expand Up @@ -114,6 +115,39 @@ func Test_createMockConfig(t *testing.T) {
checkResponseFile: true,
},
},
{
name: "generate wsdl mock with resources no script",
args: args{
generateResources: true,
forceOverwrite: true,
scriptEngine: impostermodel2.ScriptEngineNone,
anchorFileName: "pet_service",
copyWsdl: true,
checkResponseFile: false,
},
},
{
name: "generate wsdl mock with resources with script",
args: args{
generateResources: true,
forceOverwrite: true,
scriptEngine: impostermodel2.ScriptEngineJavaScript,
anchorFileName: "pet_service",
copyWsdl: true,
checkResponseFile: false,
},
},
{
name: "generate wsdl mock no resources no script",
args: args{
generateResources: false,
forceOverwrite: true,
scriptEngine: impostermodel2.ScriptEngineNone,
anchorFileName: "pet_service",
copyWsdl: true,
checkResponseFile: false,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -124,6 +158,12 @@ func Test_createMockConfig(t *testing.T) {
if tt.args.copySpecs {
prepTestData(t, configDir, testConfigPath)
}
if tt.args.copyWsdl {
err = fileutil.CopyFile(filepath.Join(testConfigPath, "pet_service.wsdl"), filepath.Join(configDir, "pet_service.wsdl"))
if err != nil {
t.Fatal(err)
}
}
impostermodel2.Create(configDir, tt.args.generateResources, tt.args.forceOverwrite, tt.args.scriptEngine, false)

if !doesFileExist(filepath.Join(configDir, tt.args.anchorFileName+"-config.yaml")) {
Expand Down
61 changes: 61 additions & 0 deletions cmd/testdata/pet_service.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:com:example:petstore"
targetNamespace="urn:com:example:petstore">

<types>
<xsd:schema targetNamespace="urn:com:example:petstore">
<xsd:element name="getPetByIdRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="getPetByIdResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:int"/>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>

<message name="getPetByIdInput">
<part name="parameters" element="tns:getPetByIdRequest"/>
</message>
<message name="getPetByIdOutput">
<part name="parameters" element="tns:getPetByIdResponse"/>
</message>

<portType name="PetServicePortType">
<operation name="getPetById">
<input message="tns:getPetByIdInput"/>
<output message="tns:getPetByIdOutput"/>
</operation>
</portType>

<binding name="PetServiceBinding" type="tns:PetServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getPetById">
<soap:operation soapAction="urn:com:example:petstore:getPetById"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

<service name="PetService">
<port name="PetServicePort" binding="tns:PetServiceBinding">
<soap:address location="http://localhost:8080/pets"/>
</port>
</service>
</definitions>
2 changes: 1 addition & 1 deletion cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func init() {
upCmd.Flags().IntVarP(&upFlags.port, "port", "p", 8080, "Port on which to listen")
upCmd.Flags().BoolVar(&upFlags.forcePull, "pull", false, "Force engine pull")
upCmd.Flags().BoolVar(&upFlags.restartOnChange, "auto-restart", true, "Automatically restart when config dir contents change")
upCmd.Flags().BoolVarP(&upFlags.scaffoldMissing, "scaffold", "s", false, "Scaffold Imposter configuration for all OpenAPI files")
upCmd.Flags().BoolVarP(&upFlags.scaffoldMissing, "scaffold", "s", false, "Scaffold Imposter configuration for all OpenAPI and WSDL files")
upCmd.Flags().StringVar(&upFlags.deduplicate, "deduplicate", "", "Override deduplication ID for replacement of containers")
upCmd.Flags().BoolVar(&upFlags.enablePlugins, "enable-plugins", true, "Enable plugins")
upCmd.Flags().BoolVar(&upFlags.ensurePlugins, "install-default-plugins", true, "Install missing default plugins")
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Flags:
-p, --port int Port on which to listen (default 8080)
--pull Force engine pull
-r, --recursive-config-scan Scan for config files in subdirectories (default false)
-s, --scaffold Scaffold Imposter configuration for all OpenAPI files
-s, --scaffold Scaffold Imposter configuration for all OpenAPI and WSDL files
-v, --version string Imposter engine version (default "latest")
```

Expand Down
20 changes: 14 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/stretchr/testify v1.11.1
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.6.0
)

require (
github.com/antchfx/xmlquery v1.5.1 // indirect
github.com/antchfx/xpath v1.3.6 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
golang.org/x/net v0.42.0 // indirect
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
Expand Down Expand Up @@ -52,6 +59,7 @@ require (
github.com/olekukonko/ll v0.0.9 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/outofcoffee/go-wsdl-parser v0.1.0
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand All @@ -78,11 +86,11 @@ require (
go.uber.org/multierr v1.9.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/mod v0.26.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/tools v0.35.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
Expand Down
Loading
Loading