api platform.com - Unsuported Media Type - api-platform.com

I just added API platform to existing Symfony 4.4 project
$ composer require api
but can't get any response in Supported Media Type from it. Documentation says it should work out of the box but I'm out of luck. Probably something is missing in my setup although it looks just like in examples:
config/packages/api_platform.yaml
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
patch_formats:
json: ['application/merge-patch+json']
swagger:
versions: [3]
Entity/Main/ContentProviders.php
/**
* ContentProviders
*
* #ORM\Table(name="content_providers", indexes={
* #ORM\Index(name="title", columns={"title"}),
* })
* #ApiResource(
* collectionOperations={"post"},
* itemOperations={
* "get"={},
* "put"
* },
* shortName="content_providers",
* normalizationContext={"groups"={"content_providers:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"content_providers:write"}, "swagger_definition_name"="Write"}
* )
* #ORM\Entity
*/
...
And if I call
curl -X GET "https://127.0.0.1:8000/api/content_providers/1" -H
"accept: application/ld+json"
It says
{"#context":"\/api\/contexts\/Error","#type":"hydra:Error","hydra:title":"An error occurred","hydra:description":"Format \u0027jsonld\u0027 not supported, handler must be implemented"
By default, JSON-LD format should be enabled https://api-platform.com/docs/core/content-negotiation/ but I also tried to add formats lines to
config/packages/api_platform.yaml
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
formats:
jsonld: ['application/ld+json']
jsonhal: ['application/hal+json']
jsonapi: ['application/vnd.api+json']
json: ['application/json']
xml: ['application/xml', 'text/xml']
yaml: ['application/x-yaml']
csv: ['text/csv']
html: ['text/html']
patch_formats:
json: ['application/merge-patch+json']
swagger:
versions: [3]
however this not helped.

Related

Is it possible to update the download location for a file in Chrome in Karate UI to the target folder? [duplicate]

Used userDataDir: 'path' in driver configure file but still files are not downloading in the specific location
Expected file to be downloaded in specific location
Can someone help me how to setup a specific path to download file in Karate in chrome like in selenium Chrome preference
You could use the experimental Browser.setDownloadBehavior Chrome DevTools Protocol method.
Here is a full example:
Feature:
Background:
* def waitForDownload = function(downloadPath) { while (!new java.io.File(downloadPath).isFile()) java.lang.Thread.sleep(1000) }
Scenario:
* configure driver = { type: 'chrome' }
* driver 'https://github.com/karatelabs/karate/releases/tag/v1.3.0'
* driver.send({ method: 'Browser.setDownloadBehavior', params: { behavior: 'allow', downloadPath: karate.toAbsolutePath('./someDir') } })
# scroll to bottom of page to ensure download link is created
* script('let x = (document.scrollingElement || document.body); x.scrollTop = x.scrollHeight')
* waitFor("a[href='/karatelabs/karate/archive/refs/tags/v1.3.0.tar.gz']").click()
* call waitForDownload karate.toAbsolutePath('./someDir/karate-1.3.0.tar.gz')

How to allow path without login on ApiPlatform?

I have the following path:
api_inventories_create_inventory_listing_collection POST ANY ANY /api/inventory/{type}
Its defined in my entity as follows:
#ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* collectionOperations={
* "get"={"security"="is_granted('ROLE_ADMIN')"},
* "create_inventory_listing"={
* "method"="POST",
* "path"="/inventory/{type}",
* "controller"=CreateSingleDeviceTypeController::class,
* },
* "post"
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_ADMIN')"},
* "delete"={"security"="is_granted('ROLE_ADMIN')"},
* "put"={"security"="is_granted('ROLE_ADMIN') or object.owner == user"},
* }
* )
As you can see, in the ApiResource, that controller has no security.
And in security.yml I allowed the path:
access_control:
- { path: ^/api/docs, roles: IS_AUTHENTICATED_ANONYMOUSLY } # Allows accessing the Swagger UI
- { path: ^/api/inventory, roles: IS_AUTHENTICATED_ANONYMOUSLY } # Allows accessing the Swagger UI
- { path: ^/authentication_token, roles: IS_AUTHENTICATED_ANONYMOUSLY }
Attached is the request via curl
curl -X POST 'https://127.0.0.1:8000/api/inventory/water' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Content-Type: application/json;charset=utf-8' \
--data '{"deviceType":"/api/device_types/2","serial":"provision"}'
and the response
{"code":401,"message":"JWT Token not found"}
you specified security attributes on the ressource level in your entity :
attributes={"security"="is_granted('ROLE_ADMIN')"},
That means their is a security, so the system will try to find a user.

Parameterized Scheduler in scripted pipeline

I switched from declerativ pipeline to scripted pipeline. Everything works fine only the Parameterized Scheduler Plugin makes problems. If i have one Trigger it works and the pipeline is scheduled. If i add another trigger only the second one works. May be it's a syntax problem but everything i tried doesn't work. Any ideas?
properties([
parameters([
booleanParam (defaultValue: true, description: 'test', name: 'test')
]),
pipelineTriggers([
parameterizedCron('15 20 * * * test=true'),
parameterizedCron('05 20 * * * test=false')
])
])//properties
according to official documentation your syntax is wrong, you are missing %. Also you can use one multiline parameterizedCron.
pipeline {
agent any
parameters {
string(name: 'PLANET', defaultValue: 'Earth', description: 'Which planet are we on?')
string(name: 'GREETING', defaultValue: 'Hello', description: 'How shall we greet?')
}
triggers {
cron('* * * * *')
parameterizedCron('''
# leave spaces where you want them around the parameters. They'll be trimmed.
# we let the build run with the default name
*/2 * * * * %GREETING=Hola;PLANET=Pluto
*/3 * * * * %PLANET=Mars
''')
}
stages {
stage('Example') {
steps {
echo "${GREETING} ${PLANET}"
script { currentBuild.description = "${GREETING} ${PLANET}" }
}
}
}
}
So in your case it should be
properties([
parameters([
booleanParam (defaultValue: true, description: 'test', name: 'test')
]),
pipelineTriggers([
parameterizedCron('''
15 20 * * * %test=true
05 20 * * * %test=false''')
])
])//properties
Also please note that there's this open issue, which indicates that for your trigger to register for the scripted, it would need to be run manually at least twice.

Webpack: How to generate separate css files from sass

Currently I have this webpack (Angular2 seed) project. With this project I have some css which depends on which client opens the page (multi brand platform).
As of now I'm generating css files using the ExtractTextPlugin, this works pretty well except for now my images etc. are all dumped in the dist root, but I can probably solve those things.
What bothers me slightly is that this also generates a "cssentrypoint.js" and "cssentrypoint.map.js". I guess it's the default behaviour but does anyone know if there is a simple solution to just generate the sass in the build script (so it still watches for changes) and not the JS?
I'll share my webpack.common config which applies to all, the out is configured to be something like [name].[chunkhash].js
/**
* #author: #AngularClass
*/
const webpack = require('webpack');
const helpers = require('./helpers');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
/*
* Webpack Plugins
*/
// problem with copy-webpack-plugin
var CopyWebpackPlugin = (CopyWebpackPlugin = require('copy-webpack-plugin'), CopyWebpackPlugin.default || CopyWebpackPlugin);
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
const HtmlElementsPlugin = require('./html-elements-plugin');
var glob = require('glob');
/*
* Webpack Constants
*/
const METADATA = {
title: 'Prepaid Service Provider',
baseUrl: '/',
isDevServer: helpers.isWebpackDevServer()
};
/*
* Webpack configuration
*
* See: http://webpack.github.io/docs/configuration.html#cli
*/
module.exports = {
/*
* Static metadata for index.html
*
* See: (custom attribute)
*/
metadata: METADATA,
/*
* Cache generated modules and chunks to improve performance for multiple incremental builds.
* This is enabled by default in watch mode.
* You can pass false to disable it.
*
* See: http://webpack.github.io/docs/configuration.html#cache
*/
//cache: false,
/*
* The entry point for the bundle
* Our Angular.js app
*
* See: http://webpack.github.io/docs/configuration.html#entry
*/
entry: {
'polyfills': './src/polyfills.browser.ts',
'vendor': './src/vendor.browser.ts',
'main': './src/main.browser.ts',
'eneco': './src/style/css/someclient.scss',
'nuon': './src/style/css/someotherclient.scss'
},
/*
* Options affecting the resolving of modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve
*/
resolve: {
/*
* An array of extensions that should be used to resolve modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
*/
extensions: ['', '.ts', '.js', 'scss'],
// Make sure root is src
root: helpers.root('src'),
// remove other default values
modulesDirectories: ['node_modules'],
alias: {
// legacy imports pre-rc releases
'angular2': helpers.root('node_modules/#angularclass/angular2-beta-to-rc-alias/dist/beta-17')
},
},
/*
* Options affecting the normal modules.
*
* See: http://webpack.github.io/docs/configuration.html#module
*/
module: {
/*
* An array of applied pre and post loaders.
*
* See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
*/
preLoaders: [
/*
* Tslint loader support for *.ts files
*
* See: https://github.com/wbuchwalter/tslint-loader
*/
// { test: /\.ts$/, loader: 'tslint-loader', exclude: [ helpers.root('node_modules') ] },
/*
* Source map loader support for *.js files
* Extracts SourceMaps for source files that as added as sourceMappingURL comment.
*
* See: https://github.com/webpack/source-map-loader
*/
{
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
// these packages have problems with their sourcemaps
helpers.root('node_modules/rxjs'),
helpers.root('node_modules/#angular'),
]
}
],
/*
* An array of automatically applied loaders.
*
* IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
* This means they are not resolved relative to the configuration file.
*
* See: http://webpack.github.io/docs/configuration.html#module-loaders
*/
loaders: [
/*
* Typescript loader support for .ts and Angular 2 async routes via .async.ts
*
* See: https://github.com/s-panferov/awesome-typescript-loader
*/
{
test: /\.ts$/,
loader: 'awesome-typescript-loader',
exclude: [/\.(spec|e2e)\.ts$/]
},
/*
* Json loader support for *.json files.
*
* See: https://github.com/webpack/json-loader
*/
{
test: /\.json$/,
loader: 'json-loader'
},
/* Raw loader support for *.html
* Returns file content as string
*
* See: https://github.com/webpack/raw-loader
*/
{
test: [/\.html$/],
loader: 'raw-loader',
exclude: [helpers.root('src/index.html')]
},
{
test: [/\.jpg$/, /\.jpeg$/, /\.png$/],
loader: 'file-loader'
},
{
test: /\.scss$/i, loader:
ExtractTextPlugin.extract(['css!sass'])
},
{
test: /\.woff(2)?(\?v=.+)?$/,
loader: "url?limit=10000&mimetype=application/font-woff&name=./fonts/[hash].[ext]"
},
{
test: /\.(ttf|eot|svg)(\?v=.+)?$/,
loader: 'file?name=./fonts/[hash].[ext]'
},
]
},
/*
* Add additional plugins to the compiler.
*
* See: http://webpack.github.io/docs/configuration.html#plugins
*/
plugins: [
/*
* Plugin: ForkCheckerPlugin
* Description: Do type checking in a separate process, so webpack don't need to wait.
*
* See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
*/
new ForkCheckerPlugin(),
/*
* Plugin: OccurenceOrderPlugin
* Description: Varies the distribution of the ids to get the smallest id length
* for often used ids.
*
* See: https://webpack.github.io/docs/list-of-plugins.html#occurrenceorderplugin
* See: https://github.com/webpack/docs/wiki/optimization#minimize
*/
new webpack.optimize.OccurenceOrderPlugin(true),
/*
* Plugin: CommonsChunkPlugin
* Description: Shares common code between the pages.
* It identifies common modules and put them into a commons chunk.
*
* See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
* See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
*/
new webpack.optimize.CommonsChunkPlugin({
name: ['polyfills', 'vendor'].reverse()
}),
/*
* Plugin: CopyWebpackPlugin
* Description: Copy files and directories in webpack.
*
* Copies project static assets.
*
* See: https://www.npmjs.com/package/copy-webpack-plugin
*/
new CopyWebpackPlugin([{
from: 'src/assets',
to: 'assets'
}]),
new ExtractTextPlugin("assets/css/[name].css", {allChunks: false}) ,
/*
* Plugin: HtmlWebpackPlugin
* Description: Simplifies creation of HTML files to serve your webpack bundles.
* This is especially useful for webpack bundles that include a hash in the filename
* which changes every compilation.
*
* See: https://github.com/ampedandwired/html-webpack-plugin
*/
new HtmlWebpackPlugin({
template: 'src/index.html',
chunksSortMode: 'dependency'
}),
/*
* Plugin: HtmlHeadConfigPlugin
* Description: Generate html tags based on javascript maps.
*
* If a publicPath is set in the webpack output configuration, it will be automatically added to
* href attributes, you can disable that by adding a "=href": false property.
* You can also enable it to other attribute by settings "=attName": true.
*
* The configuration supplied is map between a location (key) and an element definition object (value)
* The location (key) is then exported to the template under then htmlElements property in webpack configuration.
*
* Example:
* Adding this plugin configuration
* new HtmlElementsPlugin({
* headTags: { ... }
* })
*
* Means we can use it in the template like this:
* <%= webpackConfig.htmlElements.headTags %>
*
* Dependencies: HtmlWebpackPlugin
*/
new HtmlElementsPlugin({
headTags: require('./head-config.common')
})
],
/*
* Include polyfills or mocks for various node stuff
* Description: Node configuration
*
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: 'window',
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
};
Update
In addition webpack generates those JS files and also embeds them, this includes css files which I want to optionally show...

Error Symfony 3 with Monolog & swift mailer

I have a problem with swift mailer and monolog on Symfony 3.0.2:
FatalThrowableError in appDevDebugProjectContainer.php line 4963:
Type error: Argument 1 passed to SymfonyBundleMonologBundleSwiftMailerMessageFactory_0000000079e53f2b00000001716bb61a50d0bc982eb9e83148fbcc469ab36a58::__construct() must be an instance of Swift_Mailer, instance of Closure given, called in /Users/Romain/Sites/var/cache/dev/appDevDebugProjectContainer.php on line 4043
# Swiftmailer Configuration config.yml
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
#Monolog config_prod.yml
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: grouped
grouped:
type: group
members: [streamed, buffered]
streamed:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
buffered:
type: buffer
handler: swift
swift:
type: swift_mailer
from_email: no-reply#email.com
to_email: email#email.com
subject: "Subject"
level: debug
An extract appDevDebugProjectContainer.php on line 4963
/**
* {#inheritDoc}
*/
public function __construct(\Swift_Mailer $mailer, $fromEmail, $toEmail, $subject, $contentType = null)
{
static $reflection;
if (! $this->valueHolder56d41e956b1f5441039037) {
$reflection = $reflection ?: new \ReflectionClass('Symfony\\Bundle\\MonologBundle\\SwiftMailer\\MessageFactory');
$this->valueHolder56d41e956b1f5441039037 = $reflection->newInstanceWithoutConstructor();
\Closure::bind(function (\Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory $this) {
unset($this->mailer, $this->fromEmail, $this->toEmail, $this->subject, $this->contentType);
}, $this, 'Symfony\\Bundle\\MonologBundle\\SwiftMailer\\MessageFactory')->__invoke($this);
}
$this->valueHolder56d41e956b1f5441039037->__construct($mailer, $fromEmail, $toEmail, $subject, $contentType);
}
An extract appDevDebugProjectContainer.php on line 4043
/**
* Gets the 'monolog.handler.swift.mail_message_factory' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* #param bool $lazyLoad whether to try lazy-loading the service with a proxy
*
* #return \Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory A Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory instance.
*/
public function getMonolog_Handler_Swift_MailMessageFactoryService($lazyLoad = true)
{
if ($lazyLoad) {
return $this->services['monolog.handler.swift.mail_message_factory'] = new SymfonyBundleMonologBundleSwiftMailerMessageFactory_0000000057f95edf000000015dd8d44e50d0bc982eb9e83148fbcc469ab36a58(
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
$wrappedInstance = $this->getMonolog_Handler_Swift_MailMessageFactoryService(false);
$proxy->setProxyInitializer(null);
return true;
}
);
}
return new \Symfony\Bundle\MonologBundle\SwiftMailer\MessageFactory($this->get('swiftmailer.mailer.default'), 'contact#domaine.com', array(0 => 'error#domaine.com'), 'Une erreur critique est survenue', NULL);
}
Sends him of e-mail with swiftmailer only work.
I already have this configuration with the same environment but symfony 2.7 and that works.
And this configuration works on a wamp (php7) but not on my environement OSX and server Linux ...
Thank you for your help
fix with symfony 3.0.3 and monolog 1.18

Resources