Skip to content

Commit

Permalink
add option for download progress, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Aug 5, 2024
1 parent 1bea813 commit 66864f3
Show file tree
Hide file tree
Showing 31 changed files with 3,911 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/samples-cpp-qt-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Samples cpp qt client
on:
push:
branches:
- "samples/client/petstore/cpp-qt/**"
- "samples/client/petstore/cpp-qt*/**"
pull_request:
paths:
- "samples/client/petstore/cpp-qt/**"
- "samples/client/petstore/cpp-qt*/**"

env:
GRADLE_VERSION: 6.9
Expand All @@ -16,6 +16,9 @@ jobs:
name: Build cpp qt client
strategy:
matrix:
sample:
- samples/client/petstore/cpp-qt
- samples/client/petstore/cpp-qt-addDownloadProgress
os:
- ubuntu-latest
- macOS-latest
Expand All @@ -29,5 +32,5 @@ jobs:
version: "6.7.1"
target: "desktop"
- name: Build
working-directory: "samples/client/petstore/cpp-qt"
working-directory: ${{ matrix.sample }}
run: cmake . && cmake --build . --verbose
9 changes: 9 additions & 0 deletions bin/configs/cpp-qt-client-addDownloadProgress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: cpp-qt-client
outputDir: samples/client/petstore/cpp-qt-addDownloadProgress
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-addpet-only.yaml
templateDir: modules/openapi-generator/src/main/resources/cpp-qt-client
additionalProperties:
packageName: CppQtPetstoreClient
cppNamespace: test_namespace
modelNamePrefix: PFX
addDownloadProgress: true
1 change: 1 addition & 0 deletions docs/generators/cpp-qt-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|addDownloadProgress|Add support for Qt download progress| |false|
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|contentCompression|Enable Compressed Content Encoding for requests and responses| |false|
|cppNamespace|C++ namespace (convention: name::space::for::api).| |OpenAPI|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class CppQtClientCodegen extends CppQtAbstractCodegen implements CodegenC
// source folder where to write the files
protected String sourceFolder = "client";
@Setter protected boolean optionalProjectFileFlag = true;
@Setter protected boolean addDownloadProgress = false;

public CppQtClientCodegen() {
super();
Expand Down Expand Up @@ -98,6 +99,7 @@ public CppQtClientCodegen() {
// CLI options
addOption(CodegenConstants.PACKAGE_NAME, "C++ package (library) name.", DEFAULT_PACKAGE_NAME);
addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_DESC, this.optionalProjectFileFlag);
addSwitch("addDownloadProgress", "Add support for Qt download progress", this.addDownloadProgress);

supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, PREFIX + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
README.md
client/CMakeLists.txt
client/Config.cmake.in
client/PFXCategory.cpp
client/PFXCategory.h
client/PFXEnum.h
client/PFXHelpers.cpp
client/PFXHelpers.h
client/PFXHttpFileElement.cpp
client/PFXHttpFileElement.h
client/PFXHttpRequest.cpp
client/PFXHttpRequest.h
client/PFXOauth.cpp
client/PFXOauth.h
client/PFXObject.h
client/PFXPet.cpp
client/PFXPet.h
client/PFXPetApi.cpp
client/PFXPetApi.h
client/PFXServerConfiguration.h
client/PFXServerVariable.h
client/PFXTag.cpp
client/PFXTag.h
client/PFXclient.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.8.0-SNAPSHOT
150 changes: 150 additions & 0 deletions samples/client/petstore/cpp-qt-addDownloadProgress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# C++ Qt API client

#

OpenAPI Petstore

- API version: 1.0.0
- Generator version: 7.8.0-SNAPSHOT

This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.


*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*


## Requirements

Building the API client library requires:

1. CMake 3.2+
2. Qt
3. C++ Compiler

## Getting Started

example.h:
```c++

#include <iostream>
#include "../client/PFXPetApi.h"

using namespace test_namespace;

class Example : public QObject {
Q_OBJECT
PFXPet create();
public Q_SLOTS:
void exampleFunction1();
};

```
example.cpp:
```c++
#include "../client/PFXPetApi.h"
#include "example.h"
#include <QTimer>
#include <QEventLoop>
PFXPet Example::create(){
PFXPet obj;
return obj;
}
void Example::exampleFunction1(){
PFXPetApi apiInstance;
//OAuth Authentication supported right now
QEventLoop loop;
connect(&apiInstance, &PFXPetApi::addPetSignal, [&]() {
loop.quit();
});
connect(&apiInstance, &PFXPetApi::addPetSignalE, [&](QNetworkReply::NetworkError, QString error_str) {
qDebug() << "Error happened while issuing request : " << error_str;
loop.quit();
});
PFXPet pfx_pet = create(); // PFXPet | Pet object that needs to be added to the store
apiInstance.addPet(pfx_pet);
QTimer::singleShot(5000, &loop, &QEventLoop::quit);
loop.exec();
}
```

## Documentation for Servers

Parameterized Servers are supported. Define a server in the API for each endpoint with arbitrary numbers of variables:

```yaml
servers:
- url: http://{server}:{port}/{basePath}
description: Description of the Server
variables:
server:
enum:
- 'petstore'
- 'qa-petstore'
- 'dev-petstore'
default: 'petstore'
port:
enum:
- '3000'
- '1000'
default: '3000'
basePath:
default: v1
```
To change the default variable, use this function in each Api:
```c++
int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val);
```
The parameter "serverIndex" will choose a server from the server list for each endpoint. There is always at least one server with index 0. The Parameter "operation" should be the desired endpoint operationid.
Variable is the name of the variable you wish to change and the value is the new default Value.
The function will return -1 when the variable does not exists, -2 if value is not defined in the variable enum and -3 if the operation is not found.

If your endpoint has multiple server objects in the servers array, you can set the server that will be used with this function:
```c++
void setServerIndex(const QString &operation, int serverIndex);
```
Parameter "operation" should be your operationid. "serverIndex" is the index you want to set as your default server. The function will check if there is a server with your index.
Here is an example of multiple servers in the servers array. The first server will have index 0 and the second will have index 1.
```yaml
servers:
- url: http://{server}:8080/
description: Description of the Server
variables:
server:
enum:
- 'petstore'
- 'qa-petstore'
- 'dev-petstore'
default: 'petstore'
- url: https://localhost:8080/v1
```

## Documentation for Authorization

Authentication schemes defined for the API:
### petstore_auth


- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
- **Scopes**:
- write:pets: modify pets in your account
- read:pets: read your pets


## Author




## License

Apache-2.0 for more information visit [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0.html)
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.5)

project(CppQtPetstoreClient)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network Gui)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Gui)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

add_library(${PROJECT_NAME}
PFXCategory.h
PFXPet.h
PFXTag.h
PFXPetApi.h
PFXHelpers.h
PFXHttpRequest.h
PFXObject.h
PFXEnum.h
PFXHttpFileElement.h
PFXServerConfiguration.h
PFXServerVariable.h
PFXOauth.h
PFXCategory.cpp
PFXPet.cpp
PFXTag.cpp
PFXPetApi.cpp
PFXHelpers.cpp
PFXHttpRequest.cpp
PFXHttpFileElement.cpp
PFXOauth.cpp
)

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui

)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)

install(
FILES ${HEADER_FILES}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

install(
EXPORT ${PROJECT_NAME}Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake)

check_required_components("@PROJECT_NAME@")
Loading

0 comments on commit 66864f3

Please sign in to comment.