Generate embed doc - api-platform.com

can you help me please how generate correct doc if i want post data and add relation to other entity ?
I have workspace and notes. I want create new note, add it to workspace and in same time edit layout in workspace. This procedure working. But i can not figure how to show what is needed in doc.
This is what i write to body and it working
This is what showing doc if open doc
Group: 'post:write' is for write POST
StickyNote entity
#[Post(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'd.m.Y H:i:s', 'groups' => ['post:read']],
denormalizationContext: ['groups' => ['post:write']],
)]
class StickyNote extends Dates
{
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
#[ORM\CustomIdGenerator(class: UuidV4::class)]
#[Groups(['post:read', 'getSingle:workspace:read'])]
private UuidV4 $id;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['post:read', 'getSingle:workspace:read', 'post:write'])]
private ?string $noteData = null;
#[ORM\ManyToOne(inversedBy: 'stickyNotes')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['post:write'])]
#[ApiProperty(types: 'object')]
private Workspace $workspace;
Workspace entity
class Workspace extends Dates
{
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
#[ORM\CustomIdGenerator(class: UuidV4::class)]
#[Groups(['getCollection:workspace:read', 'getSingle:workspace:read'])]
private UuidV4 $id;
#[ORM\Column(length: 255, nullable: false)]
#[Groups(['getCollection:workspace:read', 'getSingle:workspace:read'])]
private string $title;
#[ORM\Column(type: 'json', nullable: true)]
#[Groups(['getCollection:workspace:read', 'getSingle:workspace:read', 'post:write'])]
private array $layout = [];
#[ORM\OneToMany(mappedBy: 'workspace', targetEntity: StickyNote::class)]
#[Groups(['getCollection:workspace:read', 'getSingle:workspace:read'])]
private Collection $stickyNotes;
#[ORM\ManyToOne(inversedBy: 'workspaces')]
private User $user;
#[ORM\Column]
#[Groups(['getCollection:workspace:read'])]
private int $ord;
Tried search in doc, google and stack .. etc .. I can get it.
I will be grateful for your help

Related

Xamarin open id login with Google

I'm setting up an open id login for Google en Microsoft and use the IdentityModel.OidcClient. I've been able to make it work for Microsoft, but the Google login doesn't return any tokens (they are all null). I followed [this tutorial][1]. To make the Microsoft login work, I needed to add ProviderInformation.UserInfoEndpoint to the OidcClientOptions. This was not mentioned in the tutorial.
I hoped the same trick would arrange things for Google too, but it didn't. So now I'm stuck with the Google login and I don't see what's missing. I hope someone else can give me that last push in the back.
One thing I noticed and find quite strange: if I add the client secret to my OidcClientOptions, I don't get a token back for the Microsoft login. If I remove it, all tokens (identity token, acces token etc) are returned.
This is the code I used to create the OidcClient object with all the options:
private OidcClient CreateOidcClient(string authorityUrl, string clientId, string scope, string redirectUrl, string issuerName, string tokenEndpoint, string authorizeEndpoint, string userInfoEndPoint, string? clientSecret = null)
{
var options = new OidcClientOptions
{
Authority = authorityUrl,
ClientId = clientId,
ClientSecret = clientSecret,
Scope = scope,
RedirectUri = redirectUrl,
Browser = new WebAuthenticatorBrowser(),
ProviderInformation = new ProviderInformation
{
IssuerName = issuerName,
KeySet = new JsonWebKeySet(),
TokenEndpoint = tokenEndpoint,
AuthorizeEndpoint = authorizeEndpoint,
UserInfoEndpoint = userInfoEndPoint,
}
};
var oidcClient = new OidcClient(options);
return oidcClient;
}
This is the code I use when you click the "Sign in with Google" button:
private async Task GoogleLogIn()
{
OidcClient oidcClient = CreateOidcClient(
GoogleConfiguration.AuthorizeUrl,
GoogleConfiguration.ClientId,
GoogleConfiguration.Scope,
GoogleConfiguration.RedirectUrl,
GoogleConfiguration.IssuerName,
GoogleConfiguration.TokenEndpoint,
GoogleConfiguration.AuthorizeEndpoint,
GoogleConfiguration.UserInfoEndpoint,
GoogleConfiguration.ClientSecret
);
LoginResult loginResult = await oidcClient.LoginAsync(new LoginRequest());
}
And finally the GoogleConfiguration:
public static class GoogleConfiguration
{
public static readonly string AuthorizeUrl = "https://accounts.google.com/o/oauth2/v2/auth";
public static readonly string ClientId = "XXXXXXXXX";
public static readonly string Scope = "openid profile email";
public static readonly string RedirectUrl = "XXXXXXXXX:/oauth2redirect";
public static readonly string IssuerName = "accounts.google.com";
public static readonly string TokenEndpoint = "https://www.googleapis.com/oauth2/v3/certs";
public static readonly string AuthorizeEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
public static readonly string UserInfoEndpoint = "https://openidconnect.googleapis.com/v1/userinfo";
public static readonly string ClientSecret = "XXXXXXXXX";
}
This is the WebAuthenticationCallbackActivity class:
[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTask)] // or SingleTop?
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "data_scheme_microsoft")]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "data_scheme_google")]
public class WebAuthenticationCallbackActivity : Xamarin.Essentials.WebAuthenticatorCallbackActivity
{
}
I receive following unclear error when the loginResult gets returned:
Error redeeming code: Not Found / no description
Any help is very much appreciated! If you need additional information, just let me know.
[1]: https://mallibone.com/post/xamarin-oidc
I am not an expert, but lately succeeded in making the same sample code work against Google.
Along the way, I have got:
Error redeeming code: Unauthorized / Unauthorized
But then I realised that I am setting client secret that I had got from a different identity provider but Google. Google does not give a client secret when you create a client ID, does it?
I fixed it and now am able to get tokens.
I finally figured it out: some credentials had been changed while I was working on this project. I didn’t notice because the old and new credentials looked very very very similar. A simple copy & paste did the trick.

Life cycle callback prePersist not firing (using YAML files)

I'm learning Symfony following The Book. In the tutorial, I successfully configured prePersist events (to set the createdAt field at insert time).
Now I'm trying to do the same but with YAML files instead of annotations. Here my orm.yml file:
AppBundle\Entity\Chronicle:
type: entity
table: chronicles
id:
id:
type: integer
generator: {strategy: AUTO}
fields:
name:
type: string
length: 256
createdAt:
type: datetime
manyToOne:
creator:
targetEntity: User
inversedBy: chronicles
joinColumn:
name: user_id
referencedColumnName: id
game:
targetEntity: Game
joinColumn:
name: game_id
referencedColumnName: id
oneToMany:
characters:
targetEntity: Character
mappedBy: chronicle
lifeCycleCallbacks:
prePersist: [ setCreatedAtValue ]
And this is a snippet of my entity class:
class Chronicle
{
private $id;
private $name;
private $createdAt;
// Associations
private $game;
private $creator;
private $characters;
// TODO: users or user relationships
// Constructor
public function __construct(User $creator=null) {
$this->characters = new ArrayCollection();
$this->creator = $creator;
}
/**
* Set createdAt at the current time.
*
* (Lifecycle callback)
*/
public function setCreatedAtValue()
{
$this->createdAt = new \DateTime();
}
// ...
}
But the setCreatedAtValue() method is never called. So, I get an exception when I try to insert an object.
I have noticed that when using annotations I have to tell about the existence of lifecycle callbacks with the #ORM\HasLifecycleCallbacks() annotation, but I have not found anywhere an equivalent to that in yml, or if that is needed.
In a tutorial I have found I should register the callback in services.yml, but the tutorial never mention it, and I haven't found it anywhere else.
It will be called if you change "lifeCycleCallbacks" to "lifecycleCallbacks".

Custom Nunit Category not showing properly in Test Explorer

I'm trying to create a custom category for my tests, so we can list the requirements the tests are specifically testing. Goal: Change the requirements, or a section of code that a requirement hits, then run the tests for that requirement. It also helps us keep track of tests so they're not duplicated. (we have over 400 requirements).
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public class RequirementAttribute : CategoryAttribute
{
protected string requirementName;
public RequirementAttribute(string name)
{
this.requirementName = name.Trim();
}
protected RequirementAttribute()
{
this.requirementName = this.GetType().Name;
if (requirementName.EndsWith("Attribute"))
requirementName = requirementName.Substring(0, requirementName.Length - 9);
}
public new string Name
{
get { return requirementName; }
}
}
This is the code I"m using, which allows me to have a a test with multiple Requirements:
[Requirement("000124")]
[Requirement("000382")]
[Requirement("000612")]
[Category("Foo")]
public void TestSomething(){}
This works, however in Test-Explorer I see:
Category[Foo](1)
Category[000124](1)
Category[000382](1)
Category[000612](1)
I want to see:
Category[Foo](1)
Requirement[000124](1)
Requirement[000382](1)
Requirement[000612(1)
Is this possible?
Adding Category("Requirement") to your decorations should work:
[Category("Requirement"), AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
http://msdn.microsoft.com/en-us/library/system.componentmodel.categoryattribute.aspx

How to sort results by column in associated table in Grails?

I have two domain classes with a simple one to many relationship (a Gift can have many GiftInstance), as below. I wish to retrieve all GiftInstances for a given user (and potentially other criteria), but sort the results based on the 'expired' attribute of Gift associated with each GiftInstance. How would I accomplish this? I would prefer to stay within the confines of Grails (dynamic finder, Criteria, etc) not have to execute raw SQL
class Gift {
String name;
String description;
Date expires;
}
class GiftInstance {
static belongsTo = [gift: Gift]
User user;
... other fields ...
}
you can do this via mapping in your domain class with two ways.
either set the sort and the order in Gift class like this:
class Gift {
String name;
String description;
Date expires;
static hasMany = [giftInstances: GiftInstance]
static mapping = {
giftInstances sort: "expired"
}
}
or in your GiftInstance domain class.
class GiftInstance {
static belongsTo = [gift: Gift]
User user
boolean expired
static mapping = {
sort: "expired"
}
}
yes, you can also set the order.
You can add a named query in GiftInstance
class GiftInstance {
static namedQueries = {
giftInstanceByUser { user ->
eq 'user', user
order 'gift.expires', 'asc'
}
}
}

Grails command object not validating

I'm sure this is a total noob question and I'm missing a blatant error, but here goes anyway.
I have a command object:
public class LeadCommand {
Integer OwnerId
String FirstName
String LastName
String Email
String Phone1
String Company
String StreetAddress1
String City
String State
String PostalCode
String Country
String Leadsource
static constraints = {
OwnerId(blank: false)
FirstName(blank: false)
LastName(blank: false)
Email(blank: false, email: true)
Phone1(blank: false)
Company(blank: false)
StreetAddress1(blank: false)
City(blank: false)
State(blank: false)
PostalCode(blank: false)
Country(blank: false)
Leadsource(blank: false)
}
}
And a controller action:
def process = { LeadCommand cmd ->
if (cmd.hasErrors()) {
redirect(action: index)
} else {
// do stuff
}
}
The command object is getting populated, but is not following the validation constraints that I setup. I've read through the docs a couple of times, but I must be missing something...
Thanks in advance
BTW - I'm using Grails 1.3.7
EDIT:
Here is some sample post data: (straight from params map)
[Phone:,
OwnerId:1,
Country:United States,
LastName:,
City:,
PostalCode:,
State:,
Email:,
Leadsource:,
FirstName:,
Submit:Submit,
Company:,
StreetAddress1:,
action:process,
controller:leadEntry]
Rename your command properties to use the standard Java naming convention of camel case with an initial lower case letter. Grails uses these conventions heavily and sometimes breaks if you don't follow them. For example:
public class LeadCommand {
Integer ownerId
String firstName
String lastName
String email
String phone1
String company
String streetAddress1
String city
String state
String postalCode
String country
String leadsource
static constraints = {
ownerId(blank: false)
firstName(blank: false)
lastName(blank: false)
email(blank: false, email: true)
phone1(blank: false)
company(blank: false)
streetAddress1(blank: false)
city(blank: false)
state(blank: false)
postalCode(blank: false)
country(blank: false)
leadsource(blank: false)
}
}

Resources